Error loading constructor in wpf format

My app is working fine, all of a sudden when loading a constructor in wpf form, im getting errors.

An object reference is not set on an object instance.

It's like it's in a loop. After pressing the enter button for a while. I am getting this error.

Microsoft Visual Studio XAML interface designer stops working.

And then I get this.

System.Runtime.Remoting.RemotingException [9980] Designer process terminated unexpectedly!

The number in square brackets changes the time evrytime.

Im using Visual Studio 2012. I am not running the app yet, I just went into designer mode from the code behind. If I compile and run the application, it works fine. Please help.

Edit:

Here are three mistakes in one image. (I cannot post more than one link)

xamlerrors

+3


source to share


2 answers


There's an error in the code or DataContext

(if you are using a ViewModel). After correcting this error, click Click here to reload the designer

. What happens is that the designer tries to load everything during design time and since there is a bug, he cannot, as if the program were actually running. This null referenced exception can be a little misleading in terms of trying to figure out the cause, because it will be thrown if you have a bug in your code or in the ViewModel.

Things to check:



  • Is your view a link to the correct ViewModel?
  • Is your piece of code in the View the same as View? Some people copy their views, but forget to change the class name in the code.
  • Do you have any errors in the ViewModel?
  • How about models? If they are loaded at design time and contain errors, this may throw the above exception.
+2


source


I noticed that errors like this are caused almost every time by

  • error in constructor without parameters
  • error in the constructor of the view model that is attached to the view

Keep in mind that when the designer loads, it calls the parameterless constructor with no view (there must be one for the designer!). If it does "complex things" that can only execute correctly at runtime, there are likely to be errors at design time.

The same is true for the view model constructor that is called from the view.


Check if development mode is active



For example, you shouldn't load data from the repository in the constructor. If you do this in the constructor, at least check if the design mode is active or not, as described in this here about the attached object GetIsInDesignMode

, and only execute the complex logic in the constructor if design mode is not active.


Debugging the problem

You also have the option to debug the problem. To do this, you need to open a second instance of Visual Studio and debug the process of creating the original instance of Visual Studio.

The process is detailed here: Debugging Exception (only) Thrown in Design View

+1


source







All Articles