question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[uwp] NullReferenceException, then XamlParseException: Cannot create instance of type...

See original GitHub issue

Describe the bug

For some user control classes, I can’t create them in xaml, an error (actually two) gets thrown. at this.InitializeComponent()

For additional context, I get this error during startup: image

Steps to reproduce the bug

This is a weird bug, and my app is really big, and it only happens on some user controls and not others, but I can’t figure out what separates the classes with the problem.

My MainPage looks like this: image

My select_sound_effect_ctrl xaml looks like this: image

At startup: First I get image

Then I get image

It basically says it can’t create an instance of type select_sound_effect_view_model, but I don’t understand why. It’s a public class, and as matter of fact, this works (just creating it in code):

image

Once again, if I leave the class as it originally is, and I create an instance in code-behind, it works: image

Expected behavior

Clearly, the error shouldn’t happen. This occurs at random times, code that once worked, sometimes stops working after months. And sure, it’s rather simple to create a control in code every now and then, but what when it’s used in a more complicated scenario, like, have an ItemsControl of such items?

Windows 10 version Saw the problem?
May 2020 Update (19041) Yes

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewleadercommented, Aug 10, 2021

Thanks for filing this, since this is a XAML issue, transferring to the WinUI XAML repo.

0reactions
github-actions[bot]commented, Jul 29, 2023

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Resolve Exception: Cannot create an instance of " ...
Currently I'm trying to work on the UWP / Universal Windows / Windows 10 User Interface in a Portable Forms / PCL setup....
Read more >
Cannot create instance of type 'Microsoft.UI.Xaml.Controls. ...
I created a new project now in which I started experimenting with UWP MenuBar. For that to work I had to add the...
Read more >
Cannot create instance of type 'Windows.UI.Xaml.Controls. ...
Last night Windows updated my computer to Build 17713.1 and the UWP C# program that ran yesterday no longer runs even though it...
Read more >
How can I fix the error: System.NullReferenceException
When you have a statement like A.B.C = E.F; , and you receive an NullReferenceException 'Object reference not set to an instance of...
Read more >
Object Reference Not Set to an Instance of an Object
This exception is thrown when you try to access a member—for instance, a method or a property—on a variable that currently holds a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found