The following exception is very frustrating when we start working with
SharePoint object model. Let us investigate how to solve the
preceding exception can be encountered in two scenarios
Scenario # 1: The above Exception in console or
- Trying to use SharePoint 2010 object model in managed application like
console or windows application.
- Trying to use SharePoint 2010 object model in WCF Service or Web
Right click on Console/Windows Application
project and select properties.
on Application tab and choose the target framework to .Net Framework
changing Target framework to .NET Framework 3.5, click on Build
the Platform target to Any CPU.
Now when you run the application,
you should not get the exception Scenario # 2: Exception when
using SharePoint 2010 object model in WCF
If you are getting the
exception while using SharePoint object model in WCF or any Web service. You
need to perform the following operations.
Host WCF service in IIS.
See the link below for step by step explanation on how to host WCF 4.0 Service
in IIS 7.5http://dhananjaykumar.net/2010/09/07/walkthrough-on-creating-wcf-4-0-service-and-hosting-in-iis-7-5/
need to make sure that the hosted WCF service is sharing the same application
pool with SharePoint.
the Application pool to SharePoint-80.
Try to apply both when you use
SharePoint 2010 object model. I hope this discussion will help you.