Qu'est-ce qui a causé la NullReferenceException dans wpfxamlloader.transformNodes ()?

StackOverflow https://stackoverflow.com/questions/4882416

  •  28-10-2019
  •  | 
  •  

Question

J'essaie de retrouver un problème qui ne se produit qu'en mode de libération et est très probablement causé par l'obscurcissement invalide de certaines propriétés. Je sais que cela se produit lors de l'initialisation d'un contrôle spécifique, mais ce contrôle est énorme. J'ai passé une journée à traverser tous les XAML et les reliures et je ne peux toujours pas voir ce qui cause cette exception.

Existe-t-il un moyen d'obtenir plus d'informations. Pour savoir ce qui a causé cette 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()
Était-ce utile?

La solution 2

Il ne semble pas possible d'obtenir un message d'exception plus détaillé. La division du XAML problématique en parties plus petites est la voie à suivre.

Autres conseils

Je ne connais pas un moyen d'obtenir un message d'exception plus détaillé, mais il pourrait au moins être utile à d'autres personnes de connaître les causes possibles. Je viens de suivre un NullReferenceException dans WpfXamlLoader.TransformNodes jusqu'à un DependencyProperty qui a été enregistré avec DependencyProperty.Register(string, Type, Type). En changeant

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

à

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

Correction du problème.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top