Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
    {
        get
        {
            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

1 Answer 1

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

 
discard

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.