tags:

views:

63

answers:

1

Hi,

Please humor me as I might be crazy.

Does viewing xaml in the Visual Studio UI designer execute the code-behind file?

For the past while whenever I try to view the main xaml file of my WPF application it throws an exception, but because I've been busy with other things I never really looked into it until today. Now I notice that in the exception's call stack it's calling many of the code-behind's methods, including methods like Window_Loaded (!). It's like it's trying to run my application while I'm designing it and obviously failing.

So I'm also wondering why it does this.

I'm also wondering how exactly I'm supposed to debug this as it's doing all this behind my back.

The actual exception comes from the fact that my application uses an unmanaged dll that it tries to use but somehow can't find it for some reason.

[Edit] I've tried moving my unmanaged DLL to Windows/System32, but I still get the same exception.

Thanks!

+2  A: 

Yes, there are things (like constructors) that get evaluated at design time. If your code is throwing an exception in the designer you can add this:

if (DesignerProperties.GetIsInDesignMode(this))
{
   return;
}
John Myczek