SIGN UP MEMBER LOGIN:    
ARTICLE
Reader Level:

The following exception is very frustrating when we start working with SharePoint object model.  Let us investigate how to solve the exception. 

1.gif 

The preceding exception can be encountered in two scenarios 
  1. Trying to use SharePoint 2010 object model in managed application like console or windows application. 
  2. Trying to use SharePoint 2010 object model in WCF Service or Web services. 
Scenario # 1: The above Exception in console or windows application 

Right click on Console/Windows Application project and select properties. 

2.gif 

Click on Application tab and choose the target framework to .Net Framework 3.5.

3.gif 

After changing Target framework to .NET Framework 3.5, click on Build tab.

4.gif
 
Change 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.5


Except we need to make sure that the hosted WCF service is sharing the same application pool with SharePoint. 

5.gif 

Select the Application pool to SharePoint-80.
 
Try to apply both when you use SharePoint 2010 object model.  I hope this discussion will help you. 

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor