Skip to content
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

Azure Functions on .NET CORE (Application Insights and SQLClient Support) #2473

Closed
tsmccartan opened this issue Feb 28, 2018 · 14 comments
Closed
Assignees

Comments

@tsmccartan
Copy link

What is the support for Application Insights with Azure Functions and .NET CORE? I have created an Azure Function for .NET Core, I did configure it to Application Insights and it is gathering telemetry. But when I try to create my own metrics using the below code, it always throws an error saying it could not load file or assembly.
Is the below supported, or is it just basic integration using log.info("Message...."); <-- This works

I have added all the nuget packages for ApplicationInsights 2.5.1

Code that causes the error:
var telemetryClient = new TelemetryClient();
telemetryClient.InstrumentationKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");

Exception:
FileLoadException: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)

@tsmccartan
Copy link
Author

Also noticed that when my Azure Function tries to use System.Data.SqlClient it gives an error with: FileLoadException: Could not load file or assembly 'System.Data.SqlClient, Version=4.2.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#x27

I can't even find this package on nuget? I have the latest installed 4.4.2, so I guess somewhere on the Azure Function .NET Core server it has this older version it is looking for? How do I resolve these missing assemblies for Azure Functions using .NET Core?

@vovikdrg
Copy link

vovikdrg commented Mar 1, 2018

@tsmccartan Azure/azure-webjobs-sdk#1472 (comment) look at this comment I had exactly the same problem and after downgrade to 4.4.0 it works

@andreapn1709
Copy link

@vovikdrg is right, i met this issue and only just 4.4.0 works, others isn't work except higher or lower, i don't know the reason, anybody can explain ?

@tsmccartan
Copy link
Author

Thanks all, the downgrade to 4.4.0 solved the SqlClient Issues. Does anybody know how to get the Application Insights to work, so you can create your own Telemetry Metric? Error says it is trying to load 2.5.1, and that is what the nuget package contains, but still this error is thrown trying to create new telemetry using the code above.

@leftside
Copy link

I have exactly the same problem with .NET Core when attempting to perform custom telemetry.

@mathewc mathewc added this to the Active Questions milestone Mar 28, 2018
@mathewc
Copy link
Member

mathewc commented Mar 28, 2018

Should be fixed with new release. Brett will verify.

@tsmccartan
Copy link
Author

@mathewc
UPDATE - I tried to add in the following code again, and it still fails with the following error.

EXCEPTION
Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

I have the following NuGet Packages Referenced:

<PackageReference Include="Microsoft.ApplicationInsights" Version="2.5.1" />
<PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.5.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta5" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="1.2.2-beta3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.0-beta5" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.0" />

@dipinbehl
Copy link

I had the same issue with 2.5.1 package of Application Insights. Had to fall back to version 2.2.0 to get it running

@jeroenwo
Copy link

Upgrading to Microsoft.ApplicationInsights v2.6.0-beta2 doesn't resolve the issue:

Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 
Could not find or load a specific file. (Exception from HRESULT: 0x80131621). 
System.Private.CoreLib: Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Downgrading to v2.4.0 seems to work, also for my other dependent packages.

<ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.4.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" Version="2.4.0" />
    <PackageReference Include="Serilog" Version="2.6.0" />
    <PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="2.2.2" />
    <PackageReference Include="Serilog.Sinks.AzureWebJobsTraceWriter-preview" Version="2.0.3-alpha" />
</ItemGroup>

But Microsoft.ApplicationInsights v2.4.0 is not NetStandard and I am getting warnings:

Warning	NU1701	
Package 'Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel 2.4.0' was restored using '.NETFramework,Version=v4.6.1' 
instead of the project target framework '.NETStandard,Version=v2.0'. 
This package may not be fully compatible with your project.	

@arerlend
Copy link

arerlend commented May 16, 2018

Using Functions v2 runtime so .NET Core, attempted to use today's LTS version of App Insights (v2.6.1) and got the same "Could not load file or assembly" error.

Reverted App Insights to v2.2 and everything loaded properly. Didn't try v2.4 though.

@fabriciosanchez @codepossible can provide .csproj w/ all dependencies if necessary.

@nzthiago

@arshadazeem
Copy link

I had to downgrade to System.Data.SqlClient Version 4.4.0 to get this working

@LarsKemmann
Copy link

Any updates on this? It's been over a year -- where do things stand now? I need to get access to a TelemetryClient instance in my FunctionsStartup class.

@brettsam
Copy link
Member

You should be able to ask for a TelemetryClient anywhere that you use DI (like in your function class constructor) and you'll get it. See a couple of "gotchas" that I just mentioned here: MicrosoftDocs/azure-docs#35181 (comment)

public Function1(TelemetryClient client)
{
}

This issue seems related to SQLClient support somehow? Is anyone still seeing that issue?

@fabiocav
Copy link
Member

Closing due to lack of response.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests