1

I used Visual Studio's NuGet tool to download and add the latest version of Google Calendar v3 APIs to my project. There are no compiler errors and the project builds. I attempt to run the following line of code and it results in an exception while loading System.Net.Primitives.dll.

User code throwing the error

CalendarService theService = new CalendarService(new Google.Apis.Services.BaseClientService.Initializer());

Background

Previously, I was able to get the APIs to function without an exception by manually rebuilding the Google API source code the against same version of System.Net.Http.Primitives all the way down to Google.Core. This was a complicated and extremely time-consuming project that I'd rather not repeat. Does anyone know why this exception is being thrown? It seems like a .NET version of DLL hell, but I would think the NuGet package would work without any issues.

Exception

FileLoadException was unhandled by user code

An exception of type 'System.IO.FileLoadException' occurred in Google.Apis.Core.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Modules Loaded

   at Google.Apis.Http.HttpClientFactory.CreateHandler(CreateHttpClientArgs args)
   at Google.Apis.Http.HttpClientFactory.CreateHttpClient(CreateHttpClientArgs args) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis.Core\Apis\Http\HttpClientFactory.cs:line 36
   at Google.Apis.Services.BaseClientService.CreateHttpClient(Initializer initializer) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:line 168
   at Google.Apis.Services.BaseClientService..ctor(Initializer initializer) in c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\Services\BaseClientService.cs:line 136
   at Google.Apis.Calendar.v3.CalendarService..ctor(Initializer initializer) in c:\code\google.com\google-api-dotnet-client\default_182\Tools\Google.Apis.NuGet.Publisher\Template\Build\Google.Apis.Calendar.v3.cs:line 1200
   at DeltaReporting.frmScheduleMaintenance.syncLocationsToProcedures() in c:\Users\Oran\Documents\Visual Studio 2010\Projects\Reporting\frmScheduleMaintenance.cs:line 268
   at DeltaReporting.frmScheduleMaintenance.btnSyncLocations_Click(Object sender, EventArgs e) in c:\Users\Oran\Documents\Visual Studio 2010\Projects\Reporting\frmScheduleMaintenance.cs:line 240
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18444 built by: FX451RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
OpenDental
    Assembly Version: 14.2.14.0
    Win32 Version: 14.2.14.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/OpenDental.exe
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
CodeBase
    Assembly Version: 7.1.0.0
    Win32 Version: 7.1.0.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/CodeBase.DLL
----------------------------------------
OpenDentBusiness
    Assembly Version: 14.2.14.0
    Win32 Version: 14.2.14.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/OpenDentBusiness.DLL
----------------------------------------
NHunspell
    Assembly Version: 0.9.6.0
    Win32 Version: 0.9.6.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/NHunspell.DLL
----------------------------------------
SparksToothChart
    Assembly Version: 4.7.1.0
    Win32 Version: 4.7.1.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/SparksToothChart.DLL
----------------------------------------
Microsoft.DirectX.Direct3D
    Assembly Version: 1.0.2902.0
    Win32 Version: 9.05.132.0000
    CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.DirectX.Direct3D/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.Direct3D.dll
----------------------------------------
xImageDeviceManager
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/xImageDeviceManager.DLL
----------------------------------------
AxInterop.AcroPDFLib
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/AxInterop.AcroPDFLib.DLL
----------------------------------------
SigPlusNET
    Assembly Version: 1.1.4050.24928
    Win32 Version: 
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/SigPlusNET.DLL
----------------------------------------
msvcm90
    Assembly Version: 9.0.30729.6161
    Win32 Version: 9.00.30729.6161
    CodeBase: file:///C:/Windows/WinSxS/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57/msvcm90.dll
----------------------------------------
System.Web.Services
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Web.Services/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
Microsoft.GeneratedCode
    Assembly Version: 1.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
MySql.Data
    Assembly Version: 6.2.4.0
    Win32 Version: 6.2.4.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/MySql.Data.DLL
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
Oracle.DataAccess
    Assembly Version: 2.112.2.0
    Win32 Version: 2.112.2.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Oracle.DataAccess.DLL
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
DeltaReporting
    Assembly Version: 7.1.0.0
    Win32 Version: 7.1.0.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/DeltaReporting.DLL
----------------------------------------
Telerik.WinControls.ChartView
    Assembly Version: 2014.1.402.40
    Win32 Version: 2014.1.402.40
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Telerik.WinControls.ChartView/v4.0_2014.1.402.40__5bb2a467cbec794e/Telerik.WinControls.ChartView.dll
----------------------------------------
Ionic.Zip
    Assembly Version: 1.9.1.4
    Win32 Version: 1.9.1.4
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Ionic.Zip.DLL
----------------------------------------
CDT
    Assembly Version: 12.3.20.0
    Win32 Version: 12.3.20.0
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/CDT.DLL
----------------------------------------
Microsoft.DirectX
    Assembly Version: 1.0.2902.0
    Win32 Version: 5.04.00.2904
    CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.DirectX/1.0.2902.0__31bf3856ad364e35/Microsoft.DirectX.dll
----------------------------------------
Microsoft.DirectX.Direct3DX
    Assembly Version: 1.0.2911.0
    Win32 Version: 9.12.589.0000
    CodeBase: file:///C:/Windows/assembly/GAC/Microsoft.DirectX.Direct3DX/1.0.2911.0__31bf3856ad364e35/Microsoft.DirectX.Direct3DX.dll
----------------------------------------
Microsoft.VisualC
    Assembly Version: 10.0.0.0
    Win32 Version: 11.00.50938.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualC/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualC.dll
----------------------------------------
Google.Apis
    Assembly Version: 1.8.1.31687
    Win32 Version: 1.8.1.31687
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Google.Apis.DLL
----------------------------------------
Google.Apis.Core
    Assembly Version: 1.8.1.31685
    Win32 Version: 1.8.1.31685
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Google.Apis.Core.DLL
----------------------------------------
System.Threading.Tasks
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Threading.Tasks/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Threading.Tasks.dll
----------------------------------------
Google.Apis.Calendar.v3
    Assembly Version: 1.8.1.84
    Win32 Version: 1.8.1.84
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Google.Apis.Calendar.v3.DLL
----------------------------------------
Newtonsoft.Json
    Assembly Version: 4.5.0.0
    Win32 Version: 4.5.11.15520
    CodeBase: file:///C:/Users/Oran/Documents/Visual%20Studio%202013/Projects/Reporting/bin/Debug/Newtonsoft.Json.DLL
----------------------------------------
System.Net.Http
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Net.Http/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Net.Http.dll
----------------------------------------
Oran D. Lord
  • 697
  • 1
  • 9
  • 23
  • Check that you are using the latest patches for .NET 4.0 (I guess you application using .NET 4.0 and not .NET 4.5). Verify also that you use the latest NuGet version and latest NuGet packages. – peleyal Jun 09 '14 at 23:00
  • One of the assemblies you are using is expecting to use System.Net.Http.Primitives, Version=1.5.0.0, but you have a different version. I guess this assembly is from System.Net.Http which is version 4.0.0.0. So you will need to add a binding redirect to your app.config or web.config. Did you see this stackoverflow post? http://stackoverflow.com/questions/18370360/could-not-load-file-or-assembly-system-net-http-primitives-located-assemblys-m – Matt Ward Jun 10 '14 at 10:06
  • The latest NuGet packages should do all that "magic" for you... Is one of the suggestions there actually helped you? – peleyal Jun 10 '14 at 13:52
  • I have tried uninstalling/reinstalling/updating the NuGet packages over and over to no avail. I manually adjusted the redirects and there was no effect. The issue appears to be that the Google.Core DLL is looking for Primitives 1.5.0.0 (strongly-typed so it will not load a different version of the module), while the rest of the DLLs are referencing the newer version. This should not be that difficult, which leads me to believe I'm missing something. – Oran D. Lord Jun 10 '14 at 14:42
  • I assume I need to copy the DLLs that start with "Google" to my program directory, but I assume that most of the other DLLs, such as those starting with "System" do not need to be copied to the program directory, since these should be available to anyone with .NET installed on their machine. Is that correct, or should I be copying **all** of the output DLLs to the bin folder of the application that uses this module? – Oran D. Lord Jun 10 '14 at 15:06

1 Answers1

2

The answer for me was to nuke and pave. I created a new project and copied my source code into the new project. Then I set up the NuGet packages, and everything began working like magic.

I will go through the differences in the files using WinMerge and see if I can figure out what the problem was with the original project, so I can update this answer.

Oran D. Lord
  • 697
  • 1
  • 9
  • 23