0

I'm trying to create a custom control using UserControl. When I drop the custom control on a window, it displays for a second then the designer crashes and I get the messag: An Exception was thrown

ArgumentNullException: Value cannot be null. Parameter name: sp

The stack trace shows an error in a call the ServiceProvider constructor.

Any idea what's going on on here? I tried this with a blank UserControl on a blank Window and got the same error. Thanks for your help.

amnesyc
  • 5,172
  • 4
  • 18
  • 19

2 Answers2

2

XAML designer will call the UserControl's constructor when loading in designer. If in the constructor or UserControl.Loaded is another Method that is not running in the design mode should be skip. In order to avoid this you can place a if condition as follows in your UserControl constructor

if(DesignerProperties.GetIsInDesignMode(this)) 
return;
// another Method that Running in RunTime

WPF user control throws design-time exception

Community
  • 1
  • 1
0

After further googling the issue, it seems that this is related to the presence of installshield projects in the solution. If I remove all installshield projects, I don't get the exception anymore. This is more of a workaround than a solution though...

amnesyc
  • 5,172
  • 4
  • 18
  • 19