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

  • SEARCH
  • Home
  • 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 8773209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:14:08+00:00 2026-06-13T18:14:08+00:00

In the static constructor of ViewModelLocator class the SimpleIoc.Default.Register<T>(); fails at IsInDesignModeStatic mode, if

  • 0

In the static constructor of ViewModelLocator class the SimpleIoc.Default.Register<T>(); fails at IsInDesignModeStatic mode, if the Interface is in a different project. As a result the MainWindow.xaml designer is empty at design time.

I’ve made a simple solution to test it. Only changes that I’ve made is to move the DataItem class and the IDataService interface into the Domain project.

Download here

I’ve found a walk-around: Add a link to the IDataService.cs in the ClientWpf project.

public class ViewModelLocator {
    static ViewModelLocator() {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        if (ViewModelBase.IsInDesignModeStatic) {

            // It fails if the IDataService is in different assembly
            // Delete the link of IDataService.cs from the ViewModel folder...
            SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
        }
        else {
            SimpleIoc.Default.Register<IDataService, DataService>();
        }

        SimpleIoc.Default.Register<MainViewModel>();
    }
...
}
  • 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-06-13T18:14:09+00:00Added an answer on June 13, 2026 at 6:14 pm
        if (ViewModelBase.IsInDesignModeStatic) {
    
    
            // put these lines here:
            if (SimpleIoc.Default.IsRegistered<IDataService>()) {
                SimpleIoc.Default.Unregister<IDataService>();
            }
    
            SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
        }
        else {
            SimpleIoc.Default.Register<IDataService, DataService>();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static class with no static constructor, but many static members. I
How can I get the ConstructorInfo for a static constructor? public class MyClass {
In what situations do I initialize a class using a static constructor ?
I have a class with a static factory constructor which returns a pointer to
I am bit confused in the usage of Static class, Private constructor and abstract
Will a static constructor on a generic class be run for every type you
Let's say I have a MySingleton class with a static constructor. I want that
When I have class containing a static constructor, is that constructor called when the
Two parts to this: If a static class can have a static constructor, why
How the static constructor is behaving here ? class a { public static int

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.