Question

I am trying to track down a problem that only happens in release mode and is most likely caused by the invalid obfuscation of some property. I know it happens when initializing a specific control but this control is huge. I have spent a day going through all the XAML and Bindings and still can't see what is causing this exception.

Is there any way to get more information. To know what caused this exception?

Exception : System.NullReferenceException
Message   : Object reference not set to an instance of an object.
Source    : PresentationFramework
Help      : 
Stack     :
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at MyClass.InitializeComponent()
Was it helpful?

Solution 2

It does not seem possible to get a more detailed exception message. Dividing the problematic XAML into smaller parts is the way to go.

OTHER TIPS

I don't know a way to get a more detailed exception message, but it might at least be useful to other people to know possible causes. I've just tracked a NullReferenceException in WpfXamlLoader.TransformNodes down to a DependencyProperty which was registered with DependencyProperty.Register(string, Type, Type). Changing

public static readonly DependencyProperty FooProperty = DependencyProperty.Register(
        nameof(Foo), typeof(object), typeof(Bar));

to

public static readonly DependencyProperty FooProperty = DependencyProperty.Register(
        nameof(Foo), typeof(object), typeof(Bar), new FrameworkPropertyMetadata(null));

fixed the problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top