NullReferenceException from InitializeComponent on upgrading to WPF 4 w/ generic type arguments-Collection of common programming errors
I just began upgrading all of our client projects to .NET 4, and we’re using WPF. All of my views inherit from a base class that extend UserControl, it is a code only base class with a single generic type argument: BaseView. Prior to upgrading to .NET 4, I simply specified the x:TypeArgument and everything worked fine, but after upgrading I now get a NullReferenceException on the InitializeComponent() call. The xaml file is set to Page and MsBuild:Compile, I tried setting it to Resource as I read somewhere but that doesn’t even build. If I create a code file that inherits from that, say AddressView : BaseView, and use that, it works just fine. Is there a way to continue to specify the type arguments in my XAML file instead?
UPDATE: Adding deeper exception/stack trace: Object reference not set to an instance of an object.
Stack Trace:
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)
UPDATE 2: Maybe you’re right, I just upgraded a separate project and it’s not getting that error on the same machine, inheriting from the same base class. That is super odd, will start removing items from the view with the issue to try to find the issue.