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?

  • 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, 2011 at 15:12
  • The logs didn't show anything helpful. Feb 20, 2012 at 15:51

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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