google-cloud-dotnet icon indicating copy to clipboard operation
google-cloud-dotnet copied to clipboard

Google.Cloud.Datastore.V1 reference to Google.Apis.Auth

Open Edvardius opened this issue 6 years ago • 6 comments

Hi! When I try to use DatastoreDb.Create(projectId); I get System.IO.FileLoadException with Google.Apis.Auth, Version=1.21.0.0. When I install 1.21.0, then the same problem appears, but with 1.41.1 version. When I update to 1.41.1, it wants 1.21.0 again. I use Google.Cloud.Datastore.V1 version 2.2.0, but I checked that after upgrading my apps from .net 4.5.2 to 4.7.2, the problem still exists in 3.0.0-beta1 of library. The assembly binding doesn't help and I think I've tried installing every possible additional "Grpc" and "Apis", but with no effect. Is there some workaround for this issue or should I wait for the finalization of the plan below to be able to use the library? https://googleapis.github.io/google-cloud-dotnet/docs/guides/gax-dependencies.html

Edvardius avatar Feb 25 '20 10:02 Edvardius

Please provide more detail about your exact context - what kind of project this is, all your dependencies etc. Assembly bindings absolutely should help here - they should tell whatever wants 1.21.0 to use 1.41.1.

If you could provide a minimal example to help us reproduce the problem, I suspect we'll be able to fix it for you.

(The plan to move away from Google.Apis.Auth is still very much only a plan, unfortunately. But it should all work fine.)

jskeet avatar Feb 25 '20 10:02 jskeet

The Google.Cloud.Datastore.V1 is used in the .NET Framework 4.5.2 class library. It's added there as PackageReference. All references to this project: image and the references to 2 internal projects, on which this project is dependent: image image This is where the error appears: image The error shows "Google.Api.Gax.Grpc" as the source. And here is the stacktrace:

at Google.Api.Gax.Grpc.ChannelPool.d__6.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.Start[TStateMachine](TStateMachine& stateMachine) at Google.Api.Gax.Grpc.ChannelPool.CreateChannelCredentialsUncached() at System.Threading.Tasks.Task1.InnerInvoke() at System.Threading.Tasks.Task.Execute() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task) at Google.Api.Gax.Grpc.ChannelPool.GetChannel(ServiceEndpoint endpoint, IEnumerable`1 channelOptions) at Google.Cloud.Datastore.V1.DatastoreDb.Create(String projectId, String namespaceId, DatastoreClient client) at CPC.Internal.BackOffice.GoogleCloudConnector.GoogleCloudDatastoreConnector.get_db() in C:\Repo\Add-Ins\CPC.Internal\CPC.Internal.BackOffice\GoogleCloudConnector\GoogleCloudDatastoreConnector.cs:line 27 at CPC.Internal.BackOffice.GoogleCloudConnector.GoogleCloudDatastoreConnector.GetItemsAsList[T](Filter filter) in C:\Repo\Add-Ins\CPC.Internal\CPC.Internal.BackOffice\GoogleCloudConnector\GoogleCloudDatastoreConnector.cs:line 122 at CPC.Internal.BackOffice.GoogleCloudConnector.GoogleCloudDatastoreConnector.GetDiaryEntries() in C:\Repo\Add-Ins\CPC.Internal\CPC.Internal.BackOffice\GoogleCloudConnector\GoogleCloudDatastoreConnector.cs:line 53 at CPC.Internal.BackOffice.CPCHoursReports.Reports.TravelReport.CreateTravelReport(Worksheet ws) in C:\Repo\Add-Ins\CPC.Internal\CPC.Internal.BackOffice\CPCHoursReports\Reports\TravelReport.cs:line 29 at CPC.Internal.BackOffice.ViewModel.OnActionMonoState(ControlIdentifier controlIdentifier) in C:\Repo\Add-Ins\CPC.Internal\CPC.Internal.BackOffice\ViewModel.cs:line 72 at CPC.AddIns.CPCInternalAddInsForExcel.Ribbon.Ribbon.OnActionMonoState(IRibbonControl control) in C:\Repo\Add-Ins\CPC.AddIns\CPCInternalAddInsForExcel\CPC.AddIns.CPCInternalAddInsForExcel\Ribbon\Ribbon.cs:line 319

Edvardius avatar Feb 25 '20 12:02 Edvardius

Sorry, it's still hard to work things out just from those screenshots. Have you been able to put together a minimal example that reproduces the problem?

jskeet avatar Feb 25 '20 12:02 jskeet

I've just tried this with a minimal example myself:

  • .NET Framework class library targeting .NET 4.5.2
  • .NET Framework console application targeting .NET 4.5.2 and referencing the library
  • Library project has a package reference to Google.Cloud.Datastore.V1
  • Library project has a public static method that calls DatastoreDb.Create and then allocates an ID to prove that we can make an RPC
  • Console project calls that static method

It all worked fine. The console project has an autogenerated set of assembly binding redirects:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Auth" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.41.1.0" newVersion="1.41.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Google.Apis.Auth.PlatformServices" publicKeyToken="4b01fa6e34db77ab" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.41.1.0" newVersion="1.41.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Interestingly, when testing the zip file I've attached here, I did find it initially failed due to a lack of gRPC libraries - but that's not the error you've got. That's fixed by adding a direct dependency from the application (the console app in this case) to Grpc.Core version 1.22.1 (or 2.27.0 for the GAX v3 libraries). Unfortunately the "old style" .NET project system isn't terribly good at transitive dependencies - I'd expect an "SDK-style" project to work better on that front. Please try this zip file though, and see whether that works for you - if it does, we'll need to work out the difference between this project and your one that can't load Google.Apis.Auth.

Issue4415.zip

jskeet avatar Feb 25 '20 13:02 jskeet

Thank you very much for the response! I've tried to install every Grpc and Google package you had in your example and with the same versions, and at that point it still didn't work. The thing that did the trick for me was adding the proper assembly bindings to the main application's app.config file, not to the class library one, so this one was my fault. But I tried doing only that without installing those additional packages and it didn't work, so I presume that installing packages with proper versions also helped.

Edvardius avatar Feb 26 '20 07:02 Edvardius

Thanks for confirming. I still don't properly understand why I only needed to add the extra package to my console app after cleaning the project - things are a little mysterious in the old school world. (As a side-note, if you get the chance to upgrade to SDK-style projects, I'd strongly encourage that :) Glad it's working for you now though!

jskeet avatar Feb 26 '20 07:02 jskeet