New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect version of Grpc is being used (package version ignored) #4527
Comments
Note: the same issue occurs using the emulator from Windows and VS2019. |
I have a simpler repro now - there's no need for the Firestore dependency. Project file: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.Auth" Version="1.21.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project> Function source: using Google.Apis.Auth.OAuth2;
using Grpc.Auth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var tokenAccess = new DummyTokenAccess();
// This succeeds
tokenAccess.ToCallCredentials();
// This fails
tokenAccess.ToChannelCredentials();
return new OkObjectResult("Passed");
}
}
class DummyTokenAccess : ITokenAccess
{
public Task<string> GetAccessTokenForRequestAsync(string authUri = null, CancellationToken cancellationToken = default)
{
throw new System.NotImplementedException();
}
}
} Exception:
This is very odd indeed:
Note that the ToCallCredentials method works. CallCredentials is in Grpc.Core.Api; ChannelCredentials is in Grpc.Core. I'm going to keep investigating this a bit to see if I can reproduce this without even a Grpc.Auth reference... |
Okay, even simpler repro - and an explanation. First, the project file: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.Core" Version="1.21.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project> Next, source code: using Grpc.Core;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
{
CreateChannelCredentials(null);
return new OkObjectResult("Passed");
}
private static ChannelCredentials CreateChannelCredentials(CallCredentials callCredentials) =>
ChannelCredentials.Create(new SslCredentials(), callCredentials);
}
} This fails with the same MissingMethodException when you try to execute CreateChannelCredentials, when the JIT compiler works on that method - because it can't find the method. The problem is that it's not loading Grpc.Core 1.21.0 at all - it's using 1.18.0 which is in If you update the So basically, this is a problem for any function needing to use a version of Grpc.Core later than the one embedded in the CLI application. |
Behind the scenes the following sequence occurs. This is because the functions runtime in azure loads that specific version of the library , but the announced dependencies are often vague. If you use features from a library newer that what is present things fail in the way described. |
Will investigate this as the version packaged with the CLI shouldn't cause this issue, so looks like there's a bug here. Do you happen to know it this is happening outside of the context of the CLI? |
@fabiocav: I don't know, I'm afraid. I assume that VS just launches the CLI? How can we test this outside the context of the CLI? |
This was just in case you had tested this on Azure or in one of the container options. Wasn't really expecting that to be the case, but thought I'd ask. I'll assign this to the next sprint and take a closer look to see what is causing the issue. |
@fabiocav I just had this problem and when @jskeet wrote "func.deps.json" it opened my eyes and I just remembered this issue: So I just added your fix for the WCF ref to my project file and boom, it worked: <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!--https://github.com/Azure/azure-functions-host/issues/3568-->
<!--<Exec Command="copy $(OutDir)bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll $(OutDir)bin\System.Private.ServiceModel.dll" />-->
<Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
</Target>
<Target Name="PostPublish" BeforeTargets="AfterPublish">
<!--https://github.com/Azure/azure-functions-host/issues/3568-->
<!--<Exec Command="copy $(PublishDir)bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll $(PublishDir)bin\System.Private.ServiceModel.dll" />-->
<Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
</Target> |
I'm trying to make this work on a mac. Is there a workaround or a solution ? |
@KasunKoswattha On a mac, the
or in my specific case, where we need to run Windows AND OSX:
However, I now have the following exception I can't seem to solve in my Azure function on OSX:
Can anyone help me figure out what this means? @jskeet ? |
@jslaybaugh: I'm afraid I can't easily tell what your context is, but I suspect it's the same underlying problem... I'm afraid I have no way of trying to support Azure Functions on a Mac. |
Thanks @jslaybaugh I will try this out. But we really need a solution for this. :( |
I ran into the issue described on StackOverflow, leading me here. Locally, both manually including a more recent package version of Grpc.Core via NuGet and the workaround posted by @andreujuanc worked. Unfortunately, neither did the trick for the remote end in the Azure cloud. Copying the dependency JSON changes nothing, while upgrading the package changes the original "Could not load type" error to Needless to say, I'm a bit confused. Why does basically every combination of proposed solutions work locally, but none of them solve the problem for the cloud runtime (which, according to some reports, shouldn't even be affected in the first place)? |
@DJ4ddi: If you've upgraded to Grpc.Core version 2.x, that would definitely cause problems for anything expecting 1.x, including (currently) all the Google Cloud client libraries. (These will soon be upgraded to Grpc.Core 2.x - at which point you won't be able to use them in the same app with anything 1.x-based, of course.) |
The symptoms were the exact same when manually installing version 1.22.1 or 1.22.0 (the exact version referenced by Google.Cloud.Dialogflow.V2). |
the workaround of copying *.deps.json work on local dev machine, but I'm still getting the error on publish to Azure Functions. |
@wikes82 me too! But only if it runs through the publish on Azure DevOps. I've got a ticket open with them now about that. If I right click and tell it to do a zip deploy from VS (Windows) it works in Azure Functions for me with the following code:
Note the |
@jslaybaugh I can't find option to do zip deploy on my VS2019 Community EDIT: NVM, I figured it out |
I'm getting the following error now I checked and the file grpc_csharp_ext.x86.dll is in /runtimes/win/native |
I fixed it by adding this line into @jslaybaugh BeforeTargets="CreateZipFile" |
Are we going to get a fix for this from Microsoft ? |
This should be resolved. The fix was pushed a bit ago in version |
Thanks @fabiocav . Let me try it out and get back to you |
Not related to the main issue, but is there any reason people are using <Exec> with copy/cp instead of <Copy> in their workarounds? Seems like a step backwards to start executing system utilities when MSBuild has built-in support. |
This is still a problem... |
I am using the NuGet package
Google.Cloud.Firestore
which relies on some other packages where type forwarding is used. The forwarded types are not found and result in aMissingMethodException
.The issue occurs when debugging locally in VS Code on macOS. I haven't deployed this yet.
The same code works in a .NET Core console app.
A lot more details at the original issue: googleapis/google-cloud-dotnet#3101
Investigative information
Repro steps
See original issue above
Expected behavior
Type forwarding is working and no
MissingMethodException
Actual behavior
MissingMethodException
when this calls into a forwarded type.Known workarounds
?
Related information
Csproj:
The text was updated successfully, but these errors were encountered: