Recieving Retrieving the COM class factory for component with CLSID {} failed due to the following error: 80040154. when running a test class cleanup

iris picture iris · Apr 17, 2012 · Viewed 7.2k times · Source

I'm having a problem with my test Solution. The tests run fine but when it come to the class and methods doing the cleaning after the tests have run, basically, deleting sharepoint groups, sites and DB index entries since I'm indexing the sites and groups on an SQL database. If I run the cleaning methods from a main, everything goes fine. Problems start when I call the methods from the ClassCleanup instead:

    [ClassCleanup()]
    public static void MyClassCleanup()
    {
        DelSphere.delGroups(SPHEREID);
        DelSphere.delSites(SPHEREID);
    }

The methods execute till the delegate:

    public static void delGroups(long sphereId)
    {

        using (SupportDB DB = new SupportDB())
        {
            var gruppi = (from grp in DB.Gruppo where grp.Sfera.PK_Sfera == sphereId select grp).ToList();
            var id = (from sphere in DB.Sfera where sphere.PK_Sfera == sphereId select sphere).ToList();

            var SC = GetSCfromSphere(id.First().PK_Sfera);
            try
            {
            Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite scSite = new SPSite(SC.SiteCollectionUrl))
                    {
                        foreach (var grp in gruppi) .....

at which point I get an exception:

    Retrieving the COM class factory for component with CLSID {BDEADF26-C265-11D0-BCED-00A0C90AB50F} failed due to the following error: 80040154.

When called on its own the method runs flawlessly only problem is when the cleanup methods makes the invocation.

Thank you.

p.s. The project is running on framework 3.5 with cpu set to ANY on a win 2008 with SP 2010.

I followed the instructions of changing the cpu execution mode to x64 from http://msdn.microsoft.com/en-us/library/ee782531.aspx but still can't run anything yet.

Error loading C:\Users\Administrator\Documents\WSTests\WSTests\bin\Debug\WSTests.dll: Unable to load the test container 'C:\Users\Administrator\Documents\WSTests\WSTests\bin\Debug\WSTests.dll' or one of its dependencies. If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///C:\Users\Administrator\Documents\WSTests\WSTests\bin\Debug\WSTests.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Answer

DoctorFoo picture DoctorFoo · Apr 17, 2012

Set the CPU to x64 and try again.