Question

I have this simple code in C# using SharePoint:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    SPSite site = new SPSite("http://localhost:333");
});

When I execute it on a Windows Server 2008 with SharePoint 2010 I get this error:

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

When I execute it on Windows Server 2003 with SharePoint 2007 it works well.

Is there a problem in Windows or Sharepoint?
How can I get rid of this error?

Was it helpful?

Solution

Was your code compiled for 64-bit?

OTHER TIPS

Try registering OWSSVR.DLL file located under ISAPI folder under 12-hive (MOSS 2007) or SharePoint root (Sharepoint 2010) folder. It is a COM library, you need to register using "REGSVR32 'FULL PATH TO DLL' command.

Goto your Visual Studio Solution Properties --> Set the Platform target as AnyCPU for Build option. It will fix the issue.

I tried the following step and it worked for me for the above error.

  • Go to Solution Explorer and press Alt+ enter
  • Select Any CPU in Build option and uncheck the box that says, Prefer 32-Bit.
  • Save the changes and Build your solution.

Now You should be able to Run the program.

Hope this helps.

For SP2010, Take reference of Microsoft.Sharepoint.dll from 14 hive.You have to rebuild the project for 64 bit

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top