SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When trying to deploy a SharePoint 2010 solution from Visual Studio 2010, I'm getting the following error:

Error occurred in deployment step 'Add Solution': The type initializer for 'Singleton' threw an exception.

The code for this class lives in another assembly and looks like this:

public class ServiceLocator<T> where T : new()
    // Other code in class left out for clarity...

    public static T Current
            return Singleton.Instance;

    class Singleton
         internal static readonly T Instance = new T();
         static Singleton() { }

The class itself has work before and I'm have been able to deploy this code, so the issue probably doesn't have something to do with the class itself.

What can be the cause of this? How can I troubleshoot this myself? Can I see more error details somewhere?

share|improve this question
Do you have the details of the actual exception? It might be in the 14/LOGS or possibly in the Event Log – Dave Wise Nov 11 '11 at 15:12
The logs didn't show anything helpful. – Christian Fredh Feb 20 '12 at 15:51
up vote 0 down vote accepted

I've figured it out.

The reason for this is that the type T can't be found. Therefore the Singleton class couldn't be loaded either. This was a servie locator (using Unity) and the mapping between the service contract and implementation was not correct, and could not load the type.

The problem can also occur if the assemblies containing the the registered service implementation are not deployed.

Still not sure why this occures in the deployment step "Add solution". It might be due to a feature receiver.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.