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

Could not load file or assembly 'Microsoft.ApplicationInsights' #118

Closed
MartinWickman opened this issue May 11, 2021 · 3 comments · Fixed by #152
Closed

Could not load file or assembly 'Microsoft.ApplicationInsights' #118

MartinWickman opened this issue May 11, 2021 · 3 comments · Fixed by #152
Labels
resolved Request has been resolved triage v0.8.0

Comments

@MartinWickman
Copy link

Adding app insights dependency and a TelemetryInitializer to the app breaks with an error

Steps to reproduce:

  1. Follow the tutorial

  2. Add Application insight packages:

    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.17.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="0.7.2-preview" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" /> 
  1. Add a Startup.cs with a ITelemetryInitializer
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using MyOpenApiFunctionApp;

[assembly: FunctionsStartup(typeof(Startup))]

namespace MyOpenApiFunctionApp
{
    using Microsoft.ApplicationInsights.Channel;
    using Microsoft.ApplicationInsights.Extensibility;
    using Microsoft.Azure.Functions.Extensions.DependencyInjection;
    using Microsoft.Extensions.DependencyInjection;

    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<ITelemetryInitializer, TelemetryInitializer>();
        }
    }
    
    public class TelemetryInitializer : ITelemetryInitializer
    {
        public void Initialize(ITelemetry item) { }
    }
}
  1. Start it
  2. Go to http://localhost:7071/api/Swagger/ui
  3. This error is displayed:
Unable to load one or more of the requested types.
Could not load file or assembly 'Microsoft.ApplicationInsights, Version=2.17.0.146, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Resolvers.OpenApiConfigurationResolver.Resolve(Assembly assembly)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiHttpTriggerContext.get_OpenApiConfigurationOptions()
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderSwaggerUI(HttpRequest req, ExecutionContext ctx, ILogger log)
@justinyoo
Copy link
Contributor

@MartinWickman Thanks for the issue! Let me have a look.

@azat-galiev
Copy link
Contributor

I've faced the same issue. It seems that some of the types in FunctionApp dll cannot be loaded because they depend on types in different assemblies which are not loaded.

I've created a minimal reproduction repository to help maintainers reproduce it.

https://github.com/GaryFreeman/AssemblyLoadMinimalReproductionFunctionApp

azat-galiev pushed a commit to azat-galiev/azure-functions-openapi-extension that referenced this issue Jun 26, 2021
@azat-galiev
Copy link
Contributor

I've made a fix of that issue. Can you have a look, please?

#152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolved Request has been resolved triage v0.8.0
Projects
None yet
3 participants