Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 389695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:53:31+00:00 2026-05-12T15:53:31+00:00

Yet another strange WPF error: I have a custom control in a simple XAML

  • 0

Yet another strange WPF error:

I have a custom control in a simple XAML page. The project builds and runs perfectly, with no errors.

Here’s the XAML:

<Window x:Class="Grapher2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:graph="clr-namespace:Grapher2"
Title="Grapher" Width="800" Height="600">

<StackPanel Name="container"  Width="700" Height="500">
    <graph:GraphCanvas x:Name="graphCanvas" Width="700" Height="500" Background="#ddd" />
</StackPanel>

But when I try to view the XAML page in the XAML designer window, I get the message:

“Problem Loading–The document contains errors that must be fixed…”

When I hit the “Reload the designer” link, an error pops up in the Error List which says:

“Object reference not set to an instance of an object”

and the line starting with “graph:GraphCanvas…” is underlined.

I was originally developing on our development server, and there, everything was the same, except the error was:

“Request for the permission of type ‘System.Security.Permissions.SecurityPermission (…blah blah… failed.)”

Again, everything works perfectly, except that I can’t view the page in the XAML designer window, which is keeping me from developing the rest of the app.

I’ve tried cleaning, building, rebuilding, and all combinations of orders of these commands, with no success.

EDIT:

Please bear in mind this is my first custom control, and I could be doing something horribly, horribly wrong. Like I said, the app compiles and works beautifully, so I’m kinda mystified.

EDIT #2:

My derived canvas is not a partial class. From my understanding of how InitializeComponent works (What does InitializeComponent() do, and how does it work in WPF?), there is no auto-generated partial class that contains InitializeComponent linked to my control. Again, the control works perfectly without it, except for breaking the XAML design view.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:53:31+00:00Added an answer on May 12, 2026 at 3:53 pm

    I had a similar issue recently. Basically my understanding is that in designer some things happens in not exactly the same order as during run-time and some things that you would think could never be null actually are null during design-time.

    I solved the problem this way: commented large parts of code in my control to the point there was no error in Cider and then uncommented them until I got the error again. Then when source of the error was localized, I surrounded problematic parts with

    if (something != null)
    {
    ...
    }
    

    Even when I felt that there’s no way that could be null. And after some time I got rid of the error.

    Not very “scientific” approach but it solved my problem. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yet another code sign error. I'm running command: xcodebuild -project $DIR/myproject.xcodeproj -sdk iphoneos5.0 -alltargets
I've just added yet another 3rd-party component to my .net project that contains a
I was handling yet another KeyDown event in a user control when I wondered
I have yet another issue which the answer is eluding me. I wish to
After getting a helpful answer here , I have run into yet another problem:
Noticed a strange thing today. I have some code like this in a project
I have a strange problem with resharper. I have a project file which is
Yet another question, go me!... Anyway, I have 2 classes with private constructors and
Yet another one of my P/Invoke questions! I have this C function: int _ei_x_new(ei_x_buff*
Yet another static question. I have read the following: What are static variables? file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.