Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.94k stars 441 forks source link

Updating ApplicationInsights to 2.18.0 causes MissingMethodException #7832

Closed lewinskimaciej closed 3 years ago

lewinskimaciej commented 3 years ago

We are trying to update our V3(netcoreapp3.1) Functions project with new AppInsights so that we can utilize FlushAsync method that was added in 2.18.0. https://github.com/microsoft/ApplicationInsights-dotnet/pull/2202

We updated all necessary nugets from 2.16.0: Microsoft.ApplicationInsights Microsoft.ApplicationInsights.AspNetCore Microsoft.Extensions.Logging.ApplicationInsights

but in runtime it still fails with:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: EventsSync
 ---> System.MissingMethodException: Method not found: 'System.Threading.Tasks.Task`1<Boolean> Microsoft.ApplicationInsights.TelemetryClient.FlushAsync(System.Threading.CancellationToken)'.
   at MWS.Core.Functions.Functions.EventsSync.RunAsync(HttpRequest req)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
   at MWS.Core.Functions.Functions.EventsSync.RunAsync(HttpRequest req)
   at lambda_method(Closure , EventsSync, Object[] )
   at Microsoft.Azure.WebJobs.Host.Executors.VoidTaskMethodInvoker`2.InvokeAsync(TReflected instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\VoidTaskMethodInvoker.cs:line 20
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`2.InvokeAsync(Object instance, Object[] arguments) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionInvoker.cs:line 52
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.InvokeWithTimeoutAsync(IFunctionInvoker invoker, ParameterHelper parameterHelper, CancellationTokenSource timeoutTokenSource, CancellationTokenSource functionCancellationTokenSource, Bool
ean throwOnTimeout, TimeSpan timerInterval, IFunctionInstance instance) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 572
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithWatchersAsync(IFunctionInstanceEx instance, ParameterHelper parameterHelper, ILogger logger, CancellationTokenSource functionCancellationTokenSource) in C:\projects\azure-webjo
bs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 518
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, Cancellat
ionToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 296
   --- End of inner exception stack trace ---
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.ExecuteWithLoggingAsync(IFunctionInstanceEx instance, FunctionStartedMessage message, FunctionInstanceLogEntry instanceLogEntry, ParameterHelper parameterHelper, ILogger logger, Cancellat
ionToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor.cs:line 343
   at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.TryExecuteAsync(IFunctionInstance functionInstance, CancellationToken cancellationToken) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\FunctionExecutor
.cs:line 105

We are using

(...)
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.13" />

<PackageReference Include="Microsoft.ApplicationInsights" Version="2.18.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.18.0" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.18.0" />
(...)

This looks like nuget didn't properly update but I made sure it did, cleared all the nuget caches, removed all bin/obj directories, even built it on a separate machine. Final assembly does contain new version of app insights so I think this is related to this bug: https://github.com/Azure/azure-functions-core-tools/issues/2399

Do you know how can we solve this? Will migration to Isolated Process and .NET 5 help with this issue in any way?

v-anvari commented 3 years ago

Hi @lewinskimaciej , While checking this internally, this could be more of an issue for -https://github.com/microsoft/ApplicationInsights-dotnet/issues. Not sure, if this is a dependency issue

lewinskimaciej commented 3 years ago

Hi @lewinskimaciej , While checking this internally, this could be more of an issue for -https://github.com/microsoft/ApplicationInsights-dotnet/issues. Not sure, if this is a dependency issue

Hi @v-anvari, issue I linked led me to believe there's some Application Insights version forced by Azure Functions/Tools?

v-anvari commented 3 years ago

Can you provide the repro steps. Also, is this on Linux

v-anvari commented 3 years ago

Hi @lewinskimaciej , Here is a tracking issue - https://github.com/Azure/azure-webjobs-sdk/issues/2779

The host hasn't been updated with the 2.18 version, the work and testing is in progress. Even if you using the latest version, when you debug, it's going to take the version in the host. Closing this issue here as this has to wait till the version has been updated. The progress will be tracked in the issue mentioned above