I'm having an issue with databinding to a service class in WPF. My service class has a static constructor that reads configuration information and pulls in some required information. The problem is that during design, I get the error the type initializer for Mytype threw an exception. I believe this is because the configuration information is not present in Visual Studio's config. When I run the app, everything works fine, but I cannot design anything because of this error.
I would presume that the design would revert to some default display if it can't get at my databinding object. Apparently it doesn't and kills the entire designer. Is there any workaround for this issue like turning off dynamic display of databound controls. This is supremently frustrating and disappointing. I am using Visual Studio 2008 SP1.
Here's a snippet of the databinding code in my grid.
<ObjectDataProvider ObjectType="{x:Type local:DataService}" x:Key="dataProvider"
MethodName="GetCollection" >
<ObjectDataProvider.MethodParameters>
<s:Int32>1</s:Int32>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
Essentially the DataService class cannot instantiate itself unless it has configuration information. I was trying to create a workaround for my particular case where the static constructor instantiates a concrete implementation of a data repository. However, I cannot directly do that since that would create a circular reference in my project. I've tried inheriting the class and catching all exceptions in the parent class' static constructor. That still doesn't work. Any other ideas on workarounds or an error log that shows more detail about what exception was thrown.
I tried stripping everything out to find the lowest common denominator. I removed the static constructor and basically returned the bare essentials. What I found was that anything that retrieved data from the database failed to render. If I return a static list, everything is fine. I'm using the microsoft enterprise library data access block. Again, the application works fine when running it. I'm assuming it can't find the required database connection information, but why would this be an issue? Microsoft had to assume this would happen when they built VS2008. Am I doing something wrong?