开发者

What caused the NullReferenceException in WpfXamlLoader.TransformNodes ()?

开发者 https://www.devze.com 2023-02-08 10:34 出处:网络
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

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 clo开发者_如何学JAVAseStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at MyClass.InitializeComponent()


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消