NullReferenceException from InitializeComponent when upgrading to WPF 4 with generic arguments

I just started updating all our client projects to .NET 4 and we are using WPF. All my views are inherited from a base class that extends UserControl, it is only a base class of code with one general argument of the type: BaseView. Before upgrading to .NET 4, I just pointed out x: TypeArgument and everything worked fine, but after upgrading now I get a NullReferenceException in the InitializeComponent () call. The xaml file has a value of "Page" and "MsBuild: compilation", I tried to set it to "Resource", as I read, but it is not even built. If I create a code file that inherits from it, say AddressView: BaseView, and use it, it works fine. Is there a way to continue to specify type arguments in my XAML file?

UPDATE: adding a deeper exception / stack trace: The object reference is not set to the object instance.

Stack trace:

in System.Windows.Markup.WpfXamlLoader.TransformNodes (XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, stack XamlContextStack`1, IStyleConnector styleConnector) in System.Windows.Markup.WpfXamlLoader.Load (XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings, Uri baseUri settings)

UPDATE 2: Perhaps you are right, I just updated a separate project and did not receive this error on the same machine inheriting from the same base class. It’s super weird starting to remove items from the problem view in order to try to find the problem.

+4
source share
2 answers

It seems like an error is being thrown into the code: you can find this by setting a higher level of exception handling in the debugger.

In Visual Studio, press Ctrl-Alt-E to open the Exceptions window, then make sure the Common Language Runtime Exceptions are marked in both columns, and then run your code.

Execution is interrupted in the line of code where the error occurs, it should be quite easy to fix (if not, publish the code and the exception text).

enter image description here

+3
source

This is a generic type argument - it worked in 3.5. From http://msdn.microsoft.com/en-us/library/ms750476.aspx :

In WPF and when setting up the .NET Framework version 4, you can use the XAML 2009 features along with x: TypeArguments, but only for free XAML (XAML that is not compiled by markup). Compiled XAML for WPF and the BAML XAML form do not currently support the keywords and features of XAML 2009. If you need markup to compile XAML, you must work under the restrictions specified in the "XAML 2006 and WPF Generic XAML Usages" section.

+2
source

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


All Articles