views:

3291

answers:

4

In my UI XAML I'm essentially inheriting from a class "BaseView" that contains functionality common to several forms, however this is preventing the designer from displaying the form: "Could not create instance of type BaseView". The code will compile and run, but it is frustrating not to be able to see the form in the Designer. Is there a better way? Thanks.

XAML:

<vw:BaseView 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:vw="clr-namespace:ReviewClient"   
    x:Class="ReviewClient.MainPage"

...

+4  A: 

The problem was that the base class was defined as abstract. This caused the designer to fail. This problem is described in more detail in the comments section of Laurent Bugnion's blog: http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx

jchadhowell
Thanks! I was just having this problem myself.
Skinniest Man
I can't see the solution, for the designer, in the link you wrote down.
Luis Filipe
+2  A: 

Another possible cause, as we just found here, so I'm adding this answer for future users, is if the project is hosted on an untrusted source, such as a file server.

In that case, the designer wouldn't load the assembly and so gave the same "Could not create instance..." error. The solution would still build and debug OK.

Andy Dent
A: 

Yet another possible cause.

I have a user control which has child controls which generate events e.g. selection_changed on list control. The select_changed event handler makes changes to other child controls.

During initialisation the selected item property of the list box gets changed and triggers a selection_changed event. The handler tries to update the other child controls but cannot because they have not yet been instantiated. This leads to a null pointer exception and causes the problem.

Once the null pointer problem was handled the control was able to be instantiated and appeared in the parent control.

paul
A: 

I have the problem that my Mvvm class have acces to the database in the constructor and that was the problem, I throws an exception. I only have to check if is runing in Desin mode.

RoQ