WPF, 'Object reference not set to an instance of an object' in Designer

后端 未结 8 2269
一个人的身影
一个人的身影 2020-12-01 08:58

I\'m getting an \"Object reference not set to an instance of an object\" error when I try to reload the Designer for my XAML UserControl. Visual Studio highlig

8条回答
  •  心在旅途
    2020-12-01 09:54

    This thread is a little old, but I had a problem I just solved with its help, so I may be able to slightly clarify some points.

    1. Have your solution loaded in Visual Studio as usual.
    2. Open a 2nd instance of VS, menu debug/attach to process/select devenv. You should see nothing spectacular! In VS 2010, i just get "Disassembly cannot be displayed in run mode."
    3. Go back to your 1st instance, where your solution is opened. Load or reload the offending XAML file. If you have a problem (I had an exception on a user control, so I could not load that window), the debugger should point the offending code in the 2nd instance. in my case, it was very clear and obvious.

    To prevent the offending code from running at design time, I used

        If System.ComponentModel.LicenseUsageMode.Runtime = 1 Then
            myObject = New ObjectDefinition
        End If
    

    Works perfectly well.

提交回复
热议问题