Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid a "object reference not set to an instance of an object" exception in XAML code at design time?

I have a problem with a wpf usercontrol which is of my own devising. The problem is that I get a object reference not set to an instance of an object exception in XAML code at design time, when I implement the usercontrol in my program.

The designer showed me the following information:

at
Microsoft.Expression.Platform.InstanceBuilders.InstanceBuilderOperations.InstantiateType(Type
type, Boolean supportInternal)    at
Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.InstantiateTargetType(IInstanceBuilderContext
context, ViewNode viewNode)    at
Microsoft.Expression.Platform.InstanceBuilders.ClrObjectInstanceBuilder.Instantiate(IInstanceBuilderContext
context, ViewNode viewNode)    at
Microsoft.Expression.WpfPlatform.InstanceBuilders.FrameworkElementInstanceBuilder.Instantiate(IInstanceBuilderContext
context, ViewNode viewNode)    at
Microsoft.Expression.WpfPlatform.InstanceBuilders.UserControlInstanceBuilder.Instantiate(IInstanceBuilderContext
context, ViewNode viewNode)    at
Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.CreateInstance(IInstanceBuilder
builder, ViewNode viewNode)

but I think these messages are not really helpful...

How can I fix or suppress this exception?

like image 226
Kimbo Avatar asked Jul 17 '13 13:07

Kimbo


People also ask

How can you avoid object reference not set to an instance of an object?

To fix "Object reference not set to an instance of an object," you should try running Microsoft Visual Studio as an administrator. You can also try resetting the user data associated with your account or updating Microsoft Visual Studio to the latest version.

What causes object reference not set to an instance of an object?

The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs.

How do I fix object reference not set to an instance of an object in VB net?

"instance of object" Means that the object is blank (or in VB speak, "Nothing"). When you are dealing with object variables, you have to create an instance of that object before referencing it. "not set to an " means that you tried to access an object, but there was nothing inside of it for the computer to access.


1 Answers

If you have 'Object reference not set to an instance of an object' in XAML, but your application compiles and runs fine, you will usually find out that its cause is something in a constructor that can't be resolved at design time.

You can just click the "Disable project code" button located on the bottom of your designer view and Visual Studio designer will stop trying to construct an instance to provide design time data view.

See here for detailed information and screenshots.

like image 101
Lirrik Avatar answered Oct 12 '22 23:10

Lirrik