Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Google.Cloud.Dialogflow.V2 Could not load file or assembly Google.Protobuf #1271

Closed
germancasares opened this issue Aug 7, 2018 · 9 comments
Assignees
Labels
type: question Request for information or clarification. Not an issue.

Comments

@germancasares
Copy link

I have created a new Azure functions projects using .net core 2.0

And when I try to reference this package it says the following:

Http Functions:

    Template: http://localhost:7071/api/Template

[2018-08-07 9:58:53 PM] Host started (1556ms)
[2018-08-07 9:58:53 PM] Job host started
[2018-08-07 9:58:53 PM] Host lock lease acquired by instance ID '0000000000000000000000007D34F7CB'.
[2018-08-07 9:59:06 PM] Executing 'Template' (Reason='This function was programmatically called via the host APIs.', Id=d2485387-4218-4fc9-8bc6-6599243eeb2b)
[2018-08-07 9:59:06 PM] Executed 'Template' (Failed, Id=d2485387-4218-4fc9-8bc6-6599243eeb2b)
[2018-08-07 9:59:06 PM] System.Private.CoreLib: Exception while executing function: Template. Project: Could not load file or assembly 'Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'Google.Protobuf, Version=3.5.1.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604'.

The function that is giving me the problem:

        [FunctionName("Template")]
        public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequest req, [Table("Template", Connection = "")]ICollector<Log> outTable)
        {
            var json= new StreamReader(req.Body).ReadToEnd();

            var request = JsonConvert.DeserializeObject<WebhookRequest>(json);

I have tried installing the Nuget package manually but that didn't work. Should I go back to .Net framework meanwhile this gets fixed or is a solution for this?

@jskeet
Copy link
Collaborator

jskeet commented Aug 7, 2018

(As an aside for the future, for Google.Cloud.* packages, the best repo to report issues is https://github.com/GoogleCloudPlatform/google-cloud-dotnet - but I'm fine to discuss this one here.)

Unfortunately I believe this is basically because Azure Functions doesn't support assembly binding redirects. Within the transitive dependencies, there are probably dependencies on different versions of Google.Protobuf. In normal environments that would be fine - NuGet would resolve to the latest version, and use assembly binding redirects for earlier versions. That doesn't work on Azure Functions.

See Azure/azure-functions-host#992 for more details, but unfortunately there's nothing we can reasonably do to fix this - we'd have to make sure that all our libraries targeted the exact same minor version of everything, including whatever version of Json.NET Azure Functions targets... it becomes infeasible pretty quickly :(

@jskeet jskeet self-assigned this Aug 7, 2018
@jskeet jskeet added the type: question Request for information or clarification. Not an issue. label Aug 7, 2018
@germancasares
Copy link
Author

Ok! Thanks for the fast response and very easy to understand!

@jskeet
Copy link
Collaborator

jskeet commented Aug 7, 2018

I'm just sorry I couldn't give better news :(

I'm hopeful that Azure Functions will get past this over time - it really needs to in order to work for modern NuGet realities.

@jskeet jskeet closed this as completed Aug 7, 2018
@paulbatum
Copy link

Hi @german95n and @jskeet - I work on Azure Functions and we've been doing a bunch of work to try to make it so that functions behaves correctly in cases like this.

I just tried this scenario out on our latest published V2 bits and I was not able to repro, but perhaps I am not following the right steps.

I made a V2 app with a http trigger, and then I referenced the DialogFlow NuGet and used it from the function:

  <ItemGroup>
    <PackageReference Include="Google.Cloud.Dialogflow.V2" Version="1.0.0-beta02" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.14" />
  </ItemGroup>
        [FunctionName("Function1")]
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
        {
            var c = AgentsClient.Create();
            return new OkObjectResult("test");
        }

I get this error:

[8/14/2018 9:30:20 PM] Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=8c1ca969-93ae-4c52-bbb0-78d8dab9aaf0)
[8/14/2018 9:30:23 PM] System.Private.CoreLib: Exception while executing function: Function1. Google.Apis.Auth: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
[8/14/2018 9:30:23 PM]
[8/14/2018 9:30:23 PM] Executed 'Function1' (Failed, Id=8c1ca969-93ae-4c52-bbb0-78d8dab9aaf0)
[8/14/2018 9:30:23 PM] System.Private.CoreLib: Exception while executing function: Function1. Google.Apis.Auth: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.

Note that its not an assembly load error. You can make sure you're running on the same version as me by looking at this output:

[8/14/2018 9:30:13 PM] Starting Host (HostId=pbatumhost-377753225, InstanceId=bcc50f76-eb56-4e0a-906d-641aaff34a98, Version=2.0.11946.0, ProcessId=35640, AppDomainId=1, Debug=True, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=)

Let me know what you find. I would like to confirm that the work we've done has helped unblock scenarios such as this one.

@jskeet
Copy link
Collaborator

jskeet commented Aug 14, 2018

@paulbatum: Could you try the JSON parsing code from the first code snippet, just with some arbitrary value? It's possible that you're running into the Auth issue before the versioning collision comes into play.

@paulbatum
Copy link

paulbatum commented Aug 14, 2018

OK, I tested with a body of just {} - this does not throw an error for me:

        [FunctionName("Function1")]
        public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
        {
            var json = new StreamReader(req.Body).ReadToEnd();
            var webhookRequest = JsonConvert.DeserializeObject<WebhookRequest>(json);            
            return new OkObjectResult("test");
        }
[8/14/2018 11:28:54 PM] Executing 'Function1' (Reason='This function was programmatically called via the host APIs.', Id=c649ed30-3f89-4716-a565-f4690c427711)
[8/14/2018 11:28:57 PM] Executed 'Function1' (Succeeded, Id=c649ed30-3f89-4716-a565-f4690c427711)

@jskeet
Copy link
Collaborator

jskeet commented Aug 15, 2018

That's interesting. @german95n could you let us know which version of Google.Cloud.Dialogflow.V2 you were using? We released a new version with new dependencies a couple of weeks ago... I wonder whether that's why @paulbatum can't reproduce the problem. (This would only be "coincidentally correct" rather than due to any changes on our part around how dependencies are managed.)

@germancasares
Copy link
Author

@paulbatum I had a previous version of the Azure Host. Updating the Azure Host to your version had solved the problem. I'm very pleased to know that I can use .Net Core now with the Azure Functions without setting the bindings explicitly.

@jskeet I was using the beta 02.

@paulbatum
Copy link

@german95n thats great!

@jskeet Please reach out if you see any other users reporting problems loading these libraries in Azure Functions V2 so that we can investigate (unfortunately we do not have a good solution for users on V1)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

3 participants