What caused the NullReferenceException in WpfXamlLoader.TransformNodes ()?

I am trying to track down a problem that occurs only in release mode and is most likely caused by the wrong confusion of some property. I know this happens when a certain control is initialized, but this control is huge. I spent the whole day on all of XAML and Bindings and still don’t see what causes this exception.

Is there a way to get more information. To find out 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() 
+4
source share
2 answers

Unable to receive a more detailed exception message. Switching to problematic XAML into smaller parts is the way to go.

+1
source

I don’t know how to get a more detailed exception message, but at least it might be helpful to other people to find out the possible reasons. I just traced a NullReferenceException in WpfXamlLoader.TransformNodes to DependencyProperty , which was registered in DependencyProperty.Register(string, Type, Type) . The change

 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 problem.

+3
source

Source: https://habr.com/ru/post/1338198/


All Articles