Uncategorized

SharePoint 2010 Development : Getting Error Cannot Add Reference to “Microsoft.SharePoint.Publishing.dll” and a fix

Recently , I stumbled into a issue while adding a reference to "Microsoft.SharePoint.Publishing.dll" assembly  in my  windows console application project . I was using  Visual Studio 2010 Beta 2 and the  project target framework is set to “3.5” (which is requirement for all SharePoint 2010 projects along with platform setting to x64)., and I am running SharePoint Server 2010 in standalone mode , on Windows Server 2008 R2.

[All screen shots are of high quality , you may need to click on them to see the clear image]

So , following is the screen shot of the error that I received.

image 

 

 

 

 

 

 

 

 

"Microsoft.SharePoint.Publishing.dll or one of its dependencies requires a latest version of .NET  Framework than one specified in the project"

What surprises me, is that I can add references to assemblies like "Microsoft.SharePoint.dll’ and "Microsoft.SharePoint.Clinet.dll"  to the project without any hassle. I finally got the fix from SharePoint MSDN forum where I posted this as a question , Paul Andrew point out that this is because in some cases (like in mine) , certain assemblies have dependency on an incorrect version of “System.Web.DataVisualization” assembly. So the fix is to simply add a reference to the correct version of “System.Web.DataVisualization” assembly. He mentioned fix this will be published in a FAQ which will be available soon. Read the thread here.

In case you are facing the same issue , you can use the steps below , I have used the screen shots to make it bit easier. The fix  worked in Visual Studio 2010 Beta 2 , but I think it should also work with Visual Studio 2005/2008 ,but as I did not test it yet in those versions I cannot say for sure.

1. In your Visual Studio project , right click “Add References” and select “Add Reference”

image

2. You need to add a reference to “System.Web.DataVisualization” assembly. Which is located at “<DRIVE-LETTER>:Program Files (x86)Microsoft  Chart ControlsAssembliesSystem.Web.DataVisualization.dll” , where “<DRIVE-LETTER>” is actual drive letter. Mine is “C” so it became “C:Program Files (x86)Microsoft  Chart ControlsAssembliesSystem.Web.DataVisualization.dll” . Following screen capture shows it.

 image

 

 

 

 

 

 

 

Now once you located the assembly path , you can provide it inside the “Add Reference”  dialog and select “System.Web.DataVisualization.dll” , click “OK”.

image

 

 

 

 

 

 

 

 

 

 

 

You should now see the assembly ““System.Web.DataVisualization”  along with other assemblies.

image

3. Now , right click “Add References” and select “Add Reference” , this time you will be adding “Microsoft.SharePoint.Publishing.dll” . This assembly is located at

<DRIVE-LETTER>Program FilesCommon FilesMicrosoft Sharedweb server extensions14ISAPI” , where “<DRIVE-LETTER>” is the drive where SharePoint Server 2010 in installed. Mine was in “C” so it becomes “C:Program FilesCommon FilesMicrosoft Sharedweb server extensions14ISAPI”. See the screen shot below.

image

Once you know the path , use it to add reference to “Microsoft.SharePoint.Publishing.dll”. Cick “OK”  , you might see the dialog with the original error message , just ignore it and click “Yes” .  See the screen shot below.

image

You should now able to use “Microsoft.SharePoint.Publishing” assembly with all its classes and methods without any issues.

I had compiled and test the codes and they are working fine.  Following are the two screen shots of a simple code using the Publishing assembly.

Compile successful without issues

  image

Code executes without any issues

image

 

Cheers

Razi