Hammy
Hammy

Reputation: 109

Unable to run Google Cloud PubSub in c#, DLL problems

I am working on integrating Google Cloud PubSub into my c# project, I used NuGet to install 1.0.0-beta11, no errors at all. When I run my project and when it reaches the code that uses pubsub, I get the following error:

An unhandled exception of type 'System.IO.FileLoadException' occurred in 
 Google.Api.Gax.dll

Additional information: Could not load file or assembly 'Google.Apis.Auth, Version=1.21.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

NuGet did install all the dependencies including Google.Apis.Auth.dll, but it's 1.27.1. I have tried everything I could think of, including grabbing 1.21.0 of that dll and using that, but no success. I have been able to run the .net sample just fine with no error.

Any thoughts? Let me know if you need more info

Upvotes: 5

Views: 2175

Answers (3)

InUser
InUser

Reputation: 1137

Old issue but maybe will help someone in the future. Was stuck with it also, it's indeed the bindingRedirect issue. In my case it was that the app.config was at the wrong level, just at the project level.

Good luck

Upvotes: 1

Mr_Sven
Mr_Sven

Reputation: 11

You can append the following to your app.config file.

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Google.Apis.Auth" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
      <bindingRedirect oldVersion="1.21.0.0-1.35.1.0" newVersion="1.35.1.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Upvotes: 1

Jon Skeet
Jon Skeet

Reputation: 1503869

Okay, I've found the reference to Google.Apis.Auth 1.21.0 - it's in the Grpc.Auth NuGet package.

If you just add a reference to the Grpc.Auth DLL, you'll get this kind of failure - but if you manage all the dependencies via NuGet, I'd expect it to be okay - it should add assembly binding redirects for you.

Without knowing your exact setup, it's quite tricky to say more than that - it could be that your library needs assembly binding redirects, but the application is in control of them... and in particular, if your application only has a reference to the library DLL, that would cause the problem.

As a workaround, you could either manually add the assembly binding redirects (the exact way of doing that will depend on the application type) or just add a reference to Google.Cloud.PubSub.V1 in the application as well as the library, at which point NuGet will do all the dependency handling for you.

Upvotes: 2

Related Questions