1

I am using System.Net.Http.Formatting in a webpart on a Sharepoint server but i am getting the below error. I understand that it is part of the MVC framework and I reference it through C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.Formatting.dll but MVC is not installed on the Sharepoint server. It is installed on my dev server and my solution works fine in the dev server but not on the Sharepoint server with no MVC. Can someone please tell me how can i reference it in the visual studio solution so that it works without instaling MVC framework

The solution which uses the assembly System.Net.Http.Formatting is a Class library which is used by the Sharepoint Web Part.

Error: Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 

I tried Copy Local to true for the assembly but I get the same error.

Using Visual Studio 2013

SP1
  • 1,182
  • 3
  • 22
  • 47

2 Answers2

1

Can you try to copy this DLL to GAC on SharePoint server using gacutil ? If not, let do so.

  1. Copy System.Net.Http.Formatting.dll to SharePoint server, supposed E drive

  2. Open cmd and run

    gacutil /i "E:\System.Net.Http.Formatting.dll"

If you can not find gacutil, probably It is located in

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\x64
trungk18
  • 19,744
  • 8
  • 48
  • 83
0

I had a similar problem recently and found this thread. As stated you need to install the dependency (DLL) in the Global Assembly Cache (GAC). You can do this in Visual Studio using the 'Package' settings. Go to Package/Package.package in the Solution Explorer. Then hit the 'Advanced' tab and add any dependencies you need through the UI there. In my case selected the dependency DLLs I needed from under the 'packages' folder created in the root of the solution by the NuGet package manager.

Next time you deploy your solution it will include those dependencies in the deployment to SharePoint. I'm no .NET expert so it took me quite some time to figure this out and I don't know about best practice for doing this, but it certainly worked well for me.

ses
  • 158
  • 1
  • 7