Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DesignTime only Error: WPF "StaticExtension" exception

I have this ComboBox

<ComboBox Name="company" Width="120" 
                  HorizontalAlignment="Right" Margin="5" 
                  IsSynchronizedWithCurrentItem="True" 
                  ItemsPanel="{DynamicResource Virtualized}" 
                  ItemsSource="{x:Static local:Repository.Customers}" 
                  SelectedItem="{Binding Path=SelectedCustomer}" 
                  DisplayMemberPath="CM_FULL_NAME""/>

It runs. It works. Except in the designer, which won't let me do anything because of the error:

ArgumentException was thrown on "StaticExtention": Exception has been thrown by the target of an invocation.

Detail

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

I have tried several things in the static class to skip the constructor in designtime, none of which fix the error:

if (LicenseManager.UsageMode == LicenseUsageMode.DesignTime)
if (DesignerProperties.GetIsInDesignMode(this))
if (System.Reflection.Assembly.GetExecutingAssembly().Location.Contains("VisualStudio"))

And returning in the constructor if any of these are true. Still getting the error.

Edit: Not sure if it makes any difference, but the static repository class uses EF4 to get from a database.

Edit2: Also tried ItemsSource {Binding} to the static lists, still get the same error. Note, calling it a repository is a misnomer, the lists are loaded on startup and never changed. Below answer does not work, still trying to figure this out.

Edit3: Thomas' Suggestion to debug design mode wasn't doable. I am using VS2010 Express, and the tools menu does not have an attach to process option. I still don't know why this breaks the designer and works in runtime.

like image 681
Kyeotic Avatar asked Mar 05 '26 17:03

Kyeotic


2 Answers

In the getter of the Customers property, try to add this code:

if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
    return null;
like image 138
Thomas Levesque Avatar answered Mar 07 '26 11:03

Thomas Levesque


Thomas answer:

if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
return null;

Works in the static constructor.

like image 39
Kyeotic Avatar answered Mar 07 '26 09:03

Kyeotic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!