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

.NET 8 in-process model Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=8.0.0.1 #3795

Open
vladyslav-panasenko opened this issue Aug 21, 2024 · 5 comments

Comments

@vladyslav-panasenko
Copy link

Version

  • AzureFuntionTools 4.84.0-inprocess
  • Windows 11
  • .NET 8
  • Azure function V4 in-process model

Description

  • Error during Azure function startup

    • System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.DependencyModel, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
  • Serilog.AspNetCore 8.0.2 depends on Microsoft.Extensions.DependencyModel 8.0.1

  • Microsoft.Extensions.DependencyModel DLL in AzureFunctionsTools\Releases\4.84.0-inprocess\cli_x64
    image

Steps to reproduce

Run Azure function locally

FunctionApp1.zip

Startup.cs

internal class Startup : FunctionsStartup
{
    public IConfiguration Configuration { get; set; }

    public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
    {
        var fileInfo = new FileInfo(Assembly.GetExecutingAssembly().Location);
        var path = fileInfo.Directory.Parent.FullName;
        var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")?.ToLower() ?? "dev";

        Configuration = builder.ConfigurationBuilder
            .SetBasePath(path)
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
            .AddJsonFile($"appsettings.{environment}.json", optional: true, reloadOnChange: true)
            .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();
    }

    public override void Configure(IFunctionsHostBuilder builder)
    {
        ConfigureServices(builder.Services);
    }

    private void ConfigureServices(IServiceCollection services)
    {
        var configReaderOptions = new ConfigurationReaderOptions(ConfigurationAssemblySource.AlwaysScanDllFiles)
        {
            SectionName = ConfigurationLoggerConfigurationExtensions.DefaultSectionName,
        };

        var logger = new LoggerConfiguration()
           .ReadFrom.Configuration(Configuration, configReaderOptions)
           .Enrich.FromLogContext()
           .Enrich.WithCorrelationId()
           .Enrich.WithExceptionDetails()
           .CreateLogger();

        services.AddLogging(lb => lb.AddSerilog(logger));
    }

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
    <PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
    <PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
    <PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Simple HTTP trigger

    public class Function1
    {
        private readonly ILogger<Function1> _logger;
        public Function1(ILogger<Function1> logger)
        {
            _logger = logger;
        }

        [FunctionName("Function1")]
        public async Task<IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req)
        {
            _logger.LogInformation("C# HTTP trigger function processed a request.");

            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            _logger.LogInformation(requestBody);
            
            return new OkObjectResult(requestBody);
        }
    }
@vladyslav-panasenko
Copy link
Author

@mattchenderson, Is it possible for someone to investigate this matter?

@vladyslav-panasenko
Copy link
Author

I tried using the latest Azure functions tools (4.97.0) and Microsoft.NET.Sdk.Functions 4.5.0. Same issue. Any suggestions?

@surgupta-msft
Copy link
Contributor

Closing as duplicate of #3829. Please use that issue for tracking.

@vladyslav-panasenko
Copy link
Author

@surgupta-msft Hello, Based on your comment in the 3829, it looks like two separate issues to me.
In my case "FUNCTIONS_INPROC_NET8_ENABLED": "1" is presented in local.settings.json.
The project is attached to the ticket as a zip.

@surgupta-msft
Copy link
Contributor

Reopening the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants