I'm getting an "Object reference is not set to an instance of an object" in some styling/templating XAML code. I did what what this guy suggested and attached a second instance of Visual Studio to debug it. Sure enough, the exception popped up when I did a whitespace change and saved it.
However, it's not like it helps much. Here's the inner NullReferenceException's stacktrace:
at Microsoft.Expression.DesignSurface.View.SceneView.SaveGuidesForDocument() at Microsoft.Expression.DesignSurface.View.SceneView.PrepareDocumentForSaving() at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerView.<Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerView.PrepareDocumentForSaving>b__18() at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
And here's all the rest:
How can I tell what bug in my code is causing this NullReferenceException?
It is just by chance that I managed to find out what was wrong - certainly not thanks to any VS debugging.
Apparently if your custom control does not have a public or protected parameterless constructor, then the design will not be able to render it. In my case I had added a parameter to the default constructor, which broke the designer. If you add a default constructor but keep it private (because you intentionally want to prevent subclasses from using it) then the designer still breaks.