Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:27:52+00:00 2026-05-13T18:27:52+00:00

I’m having an issue with databinding to a service class in WPF. My service

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:27:52+00:00Added an answer on May 13, 2026 at 6:27 pm

    You’re right. The Visual Studio designer is unable to access your database connection strings. The common way of providing design-time data is to first check whether the application is in design mode and, if so, return some dummy-data without making any connections to the database.

    Something like the following

    public class DataService
    {
    
       public IList<string> GetCollection()
       {
    
          if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
          {
    
             // get data from database here
          }
          else
          {
             // return fake data for the designer
             return new List<string> {"my", "test", "data"};
          }
       }
    }
    

    The important thing is to never call upon anything that will need config if it will be used in design mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.