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 #10660

Open
vladyslav-panasenko opened this issue Oct 9, 2024 · 4 comments

Comments

@vladyslav-panasenko
Copy link

Version
AzureFuntionTools 4.91.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

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

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

@bhagyshricompany
Copy link

Hi @vladyslav-panasenko Thanks for updating will check and update you asap.Thanks

@bhagyshricompany
Copy link

Hi @jviau please comment Thanks

@jviau
Copy link
Contributor

jviau commented Dec 2, 2024

Thank you for reporting this. I have identified we were not pinning this assembly and have put up a PR to address that

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

3 participants