blazorfile-not-found

dotnet application refusing to serve .dll files in wwwroot needed by blazor webassembly


My dotnet application is refusing to serve .dll files in wwwroot application needed by Blazor web assembly. Dotnet can see the files so there is no permission issue. I think probably there is a security setting in dotnet that is preventing it from statically serving the .dll files

I even wrote this code to verify the .dll files are actually copied over by Docker and I see them:

    foreach (var file in Directory.GetFiles(Path.Join("wwwroot", "_framework")))
    {
        Console.WriteLine(file);
    }

Console log:

sudo docker run -p 8080:80 -it --rm amir734jj/symmetric-crypto-chatroom
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.dll.gz
wwwroot/_framework/System.Runtime.CompilerServices.Unsafe.dll
wwwroot/_framework/System.Collections.NonGeneric.dll
wwwroot/_framework/System.Net.WebSockets.dll
wwwroot/_framework/System.Net.Security.dll.gz
wwwroot/_framework/System.Diagnostics.FileVersionInfo.dll.gz
wwwroot/_framework/icudt_no_CJK.dat
wwwroot/_framework/System.Security.Cryptography.Algorithms.dll
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.dll
wwwroot/_framework/icudt_EFIGS.dat.gz
wwwroot/_framework/Microsoft.Extensions.Logging.dll.gz
wwwroot/_framework/NSec.Cryptography.dll.br
wwwroot/_framework/dotnet.7.0.1.pm4grxxe0f.js.gz
wwwroot/_framework/dotnet.7.0.1.pm4grxxe0f.js
wwwroot/_framework/dotnet.wasm.gz
wwwroot/_framework/System.Security.Cryptography.dll.br
wwwroot/_framework/Blazor.Extensions.Logging.dll.gz
wwwroot/_framework/System.Net.Requests.dll
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Protocols.Json.dll.gz
wwwroot/_framework/System.Runtime.InteropServices.dll
wwwroot/_framework/System.ComponentModel.dll
wwwroot/_framework/System.Collections.NonGeneric.dll.gz
wwwroot/_framework/System.IO.Pipelines.dll.gz
wwwroot/_framework/System.ComponentModel.TypeConverter.dll
wwwroot/_framework/UI.dll.gz
wwwroot/_framework/Microsoft.JSInterop.WebAssembly.dll.gz
wwwroot/_framework/System.Runtime.Serialization.Primitives.dll.gz
wwwroot/_framework/System.Collections.Specialized.dll
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Common.dll.br
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.Abstractions.dll.br
wwwroot/_framework/Blazored.SessionStorage.dll.gz
wwwroot/_framework/Microsoft.Extensions.Features.dll
wwwroot/_framework/System.Diagnostics.FileVersionInfo.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Client.dll.gz
wwwroot/_framework/Havit.Core.dll.br
wwwroot/_framework/Microsoft.Extensions.Features.dll.br
wwwroot/_framework/System.Runtime.dll.gz
wwwroot/_framework/System.ComponentModel.Primitives.dll.br
wwwroot/_framework/System.Net.WebSockets.dll.br
wwwroot/_framework/netstandard.dll.gz
wwwroot/_framework/Microsoft.Extensions.Logging.Abstractions.dll
wwwroot/_framework/System.Text.Json.dll.br
wwwroot/_framework/System.Text.RegularExpressions.dll.br
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.dll.br
wwwroot/_framework/blazor.boot.json
wwwroot/_framework/System.Collections.NonGeneric.dll.br
wwwroot/_framework/System.Runtime.dll.br
wwwroot/_framework/System.Runtime.InteropServices.JavaScript.dll.gz
wwwroot/_framework/Microsoft.Extensions.Logging.dll.br
wwwroot/_framework/Microsoft.Extensions.Logging.Abstractions.dll.gz
wwwroot/_framework/System.Security.Cryptography.Primitives.dll.br
wwwroot/_framework/System.Net.Requests.dll.br
wwwroot/_framework/System.ComponentModel.Annotations.dll.br
wwwroot/_framework/dotnet.7.0.4.im9dizu1ff.js
wwwroot/_framework/System.Linq.Queryable.dll.gz
wwwroot/_framework/System.Security.Cryptography.Primitives.dll.gz
wwwroot/_framework/Microsoft.Extensions.Localization.dll.gz
wwwroot/_framework/System.Runtime.InteropServices.dll.br
wwwroot/_framework/Microsoft.JSInterop.dll.gz
wwwroot/_framework/dotnet.7.0.1.pm4grxxe0f.js.br
wwwroot/_framework/System.Threading.Channels.dll
wwwroot/_framework/Models.dll.gz
wwwroot/_framework/System.Diagnostics.TraceSource.dll.gz
wwwroot/_framework/Microsoft.Extensions.Options.dll.gz
wwwroot/_framework/System.Net.Http.dll.br
wwwroot/_framework/System.Threading.Thread.dll
wwwroot/_framework/System.ComponentModel.Primitives.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Authorization.dll   // <---------- HERE, DLL is there
wwwroot/_framework/System.Net.Mail.dll.br
wwwroot/_framework/System.Net.Primitives.dll
wwwroot/_framework/System.Text.Encodings.Web.dll.br
wwwroot/_framework/Microsoft.Extensions.Logging.Abstractions.dll.br
wwwroot/_framework/Microsoft.Extensions.Configuration.Json.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Connections.Abstractions.dll
wwwroot/_framework/System.Runtime.InteropServices.JavaScript.dll
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.Core.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Authorization.dll.br
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.Core.dll
wwwroot/_framework/System.Security.Cryptography.Algorithms.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Components.Authorization.dll
wwwroot/_framework/dotnet.wasm.br
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.Abstractions.dll.gz
wwwroot/_framework/Havit.Blazor.Components.Web.Bootstrap.dll
wwwroot/_framework/System.Net.Mail.dll.gz
wwwroot/_framework/icudt_EFIGS.dat
wwwroot/_framework/Microsoft.JSInterop.WebAssembly.dll
wwwroot/_framework/Microsoft.Extensions.Options.dll
wwwroot/_framework/icudt_CJK.dat
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Client.dll
wwwroot/_framework/netstandard.dll.br
wwwroot/_framework/System.ComponentModel.Annotations.dll
wwwroot/_framework/icudt.dat.gz
wwwroot/_framework/Blazored.SessionStorage.dll
wwwroot/_framework/System.Runtime.InteropServices.dll.gz
wwwroot/_framework/System.Threading.Channels.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Components.Forms.dll
wwwroot/_framework/Microsoft.Extensions.Configuration.Abstractions.dll.br
wwwroot/_framework/Microsoft.Extensions.Configuration.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Components.dll
wwwroot/_framework/Blazor.Extensions.Logging.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Connections.Abstractions.dll.gz
wwwroot/_framework/System.Text.RegularExpressions.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Components.WebAssembly.dll.br
wwwroot/_framework/dotnet.timezones.blat.gz
wwwroot/_framework/System.Collections.Concurrent.dll
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Common.dll
wwwroot/_framework/Microsoft.Extensions.Configuration.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Common.dll
wwwroot/_framework/System.Linq.dll.br
wwwroot/_framework/dotnet.timezones.blat
wwwroot/_framework/Microsoft.Extensions.Primitives.dll.br
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.dll
wwwroot/_framework/Microsoft.AspNetCore.Components.Forms.dll.gz
wwwroot/_framework/System.Net.WebSockets.dll.gz
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.Abstractions.dll
wwwroot/_framework/System.Runtime.Serialization.Primitives.dll
wwwroot/_framework/System.Linq.Queryable.dll.br
wwwroot/_framework/System.Net.Http.dll.gz
wwwroot/_framework/BlazorDownloadFile.dll
wwwroot/_framework/System.Net.WebSockets.Client.dll
wwwroot/_framework/System.Security.Claims.dll.br
wwwroot/_framework/System.Private.CoreLib.dll.br
wwwroot/_framework/netstandard.dll
wwwroot/_framework/System.Threading.dll
wwwroot/_framework/System.Collections.Specialized.dll.gz
wwwroot/_framework/UI.dll.br
wwwroot/_framework/System.ComponentModel.Primitives.dll
wwwroot/_framework/System.Runtime.CompilerServices.Unsafe.dll.gz
wwwroot/_framework/System.dll.br
wwwroot/_framework/System.IO.Pipelines.dll
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Common.dll.br
wwwroot/_framework/Microsoft.Extensions.Configuration.dll
wwwroot/_framework/System.Linq.Expressions.dll.gz
wwwroot/_framework/System.Diagnostics.FileVersionInfo.dll
wwwroot/_framework/System.Linq.Expressions.dll.br
wwwroot/_framework/System.Security.Cryptography.Algorithms.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Components.dll.gz
wwwroot/_framework/Havit.Blazor.Components.Web.dll.br
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.dll.gz
wwwroot/_framework/System.Net.Primitives.dll.gz
wwwroot/_framework/icudt_no_CJK.dat.br
wwwroot/_framework/System.Text.RegularExpressions.dll
wwwroot/_framework/Microsoft.AspNetCore.Components.Web.dll.gz
wwwroot/_framework/BouncyCastle.Crypto.dll.gz
wwwroot/_framework/Microsoft.Extensions.Localization.dll
wwwroot/_framework/Microsoft.AspNetCore.Components.Authorization.dll.br
wwwroot/_framework/System.ComponentModel.TypeConverter.dll.br
wwwroot/_framework/System.Console.dll.gz
wwwroot/_framework/System.ComponentModel.dll.gz
wwwroot/_framework/System.Console.dll
wwwroot/_framework/System.Private.Uri.dll.br
wwwroot/_framework/System.Net.Mail.dll
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Protocols.Json.dll.br
wwwroot/_framework/icudt_EFIGS.dat.br
wwwroot/_framework/System.Text.Encodings.Web.dll.gz
wwwroot/_framework/System.Net.WebSockets.Client.dll.br
wwwroot/_framework/System.Diagnostics.TraceSource.dll
wwwroot/_framework/BlazorDownloadFile.dll.gz
wwwroot/_framework/BouncyCastle.Crypto.dll.br
wwwroot/_framework/Havit.Blazor.Components.Web.Bootstrap.dll.br
wwwroot/_framework/System.Memory.dll.br
wwwroot/_framework/Blazored.SessionStorage.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Connections.Abstractions.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Client.dll.br
wwwroot/_framework/Blazor.Extensions.Logging.dll
wwwroot/_framework/Models.dll.br
wwwroot/_framework/dotnet.timezones.blat.br
wwwroot/_framework/System.Security.Cryptography.dll.gz
wwwroot/_framework/System.Collections.Specialized.dll.br
wwwroot/_framework/System.Collections.dll.gz
wwwroot/_framework/NSec.Cryptography.dll.gz
wwwroot/_framework/System.Collections.dll
wwwroot/_framework/System.Text.Encoding.Extensions.dll.gz
wwwroot/_framework/blazor.webassembly.js
wwwroot/_framework/Havit.Core.dll
wwwroot/_framework/Microsoft.Extensions.Configuration.Abstractions.dll
wwwroot/_framework/Microsoft.AspNetCore.Components.Forms.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Components.dll.br
wwwroot/_framework/icudt_CJK.dat.br
wwwroot/_framework/Microsoft.AspNetCore.Components.Web.dll.br
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Protocols.Json.dll
wwwroot/_framework/System.Threading.Channels.dll.br
wwwroot/_framework/System.Linq.Expressions.dll
wwwroot/_framework/System.Memory.dll.gz
wwwroot/_framework/dotnet.wasm
wwwroot/_framework/System.Security.Claims.dll.gz
wwwroot/_framework/System.Net.Http.dll
wwwroot/_framework/System.ComponentModel.TypeConverter.dll.gz
wwwroot/_framework/Havit.Blazor.Components.Web.Bootstrap.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Components.Web.dll
wwwroot/_framework/Havit.Blazor.Components.Web.dll
wwwroot/_framework/UI.dll
wwwroot/_framework/System.Runtime.InteropServices.JavaScript.dll.br
wwwroot/_framework/System.dll
wwwroot/_framework/Microsoft.Extensions.Configuration.Abstractions.dll.gz
wwwroot/_framework/Microsoft.Extensions.Localization.Abstractions.dll.br
wwwroot/_framework/icudt.dat.br
wwwroot/_framework/System.ObjectModel.dll.gz
wwwroot/_framework/System.dll.gz
wwwroot/_framework/System.Net.Security.dll.br
wwwroot/_framework/System.IO.Pipelines.dll.br
wwwroot/_framework/System.Threading.dll.gz
wwwroot/_framework/System.Linq.dll.gz
wwwroot/_framework/System.Text.Json.dll.gz
wwwroot/_framework/System.Linq.Queryable.dll
wwwroot/_framework/System.Linq.dll
wwwroot/_framework/Microsoft.AspNetCore.Components.Authorization.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Client.Core.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Http.Connections.Common.dll.gz
wwwroot/_framework/Microsoft.Extensions.Configuration.Json.dll.gz
wwwroot/_framework/System.ObjectModel.dll.br
wwwroot/_framework/Models.pdb.gz
wwwroot/_framework/System.Text.Encodings.Web.dll
wwwroot/_framework/UI.pdb.gz
wwwroot/_framework/System.Diagnostics.TraceSource.dll.br
wwwroot/_framework/System.Security.Cryptography.Primitives.dll
wwwroot/_framework/System.Text.Json.dll
wwwroot/_framework/NSec.Cryptography.dll
wwwroot/_framework/System.ObjectModel.dll
wwwroot/_framework/Microsoft.Extensions.Localization.Abstractions.dll
wwwroot/_framework/Microsoft.Extensions.Localization.dll.br
wwwroot/_framework/Microsoft.Extensions.Logging.dll
wwwroot/_framework/dotnet.7.0.4.im9dizu1ff.js.br
wwwroot/_framework/Microsoft.Extensions.Features.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Components.WebAssembly.dll
wwwroot/_framework/System.Threading.dll.br
wwwroot/_framework/System.Net.WebSockets.Client.dll.gz
wwwroot/_framework/System.Threading.Thread.dll.br
wwwroot/_framework/blazor.boot.json.gz
wwwroot/_framework/icudt.dat
wwwroot/_framework/icudt_no_CJK.dat.gz
wwwroot/_framework/Microsoft.AspNetCore.SignalR.Common.dll.gz
wwwroot/_framework/System.Runtime.CompilerServices.Unsafe.dll.br
wwwroot/_framework/System.Console.dll.br
wwwroot/_framework/System.Collections.dll.br
wwwroot/_framework/System.Memory.dll
wwwroot/_framework/blazor.webassembly.js.br
wwwroot/_framework/System.Security.Cryptography.dll
wwwroot/_framework/System.Security.Claims.dll
wwwroot/_framework/BlazorDownloadFile.dll.br
wwwroot/_framework/Microsoft.Extensions.Primitives.dll.gz
wwwroot/_framework/System.Runtime.dll
wwwroot/_framework/System.Collections.Concurrent.dll.gz
wwwroot/_framework/System.Private.CoreLib.dll.gz
wwwroot/_framework/Microsoft.JSInterop.WebAssembly.dll.br
wwwroot/_framework/Models.dll
wwwroot/_framework/blazor.boot.json.br
wwwroot/_framework/dotnet.7.0.4.im9dizu1ff.js.gz
wwwroot/_framework/BouncyCastle.Crypto.dll
wwwroot/_framework/icudt_CJK.dat.gz
wwwroot/_framework/System.Threading.Thread.dll.gz
wwwroot/_framework/System.Private.Uri.dll.gz
wwwroot/_framework/Havit.Core.dll.gz
wwwroot/_framework/System.Net.Primitives.dll.br
wwwroot/_framework/System.Private.CoreLib.dll
wwwroot/_framework/Microsoft.Extensions.Primitives.dll
wwwroot/_framework/Microsoft.Extensions.Options.dll.br
wwwroot/_framework/blazor.webassembly.js.gz
wwwroot/_framework/System.Collections.Concurrent.dll.br
wwwroot/_framework/System.Net.Security.dll
wwwroot/_framework/Microsoft.Extensions.Configuration.Json.dll
wwwroot/_framework/Microsoft.JSInterop.dll
wwwroot/_framework/System.Net.Requests.dll.gz
wwwroot/_framework/System.Private.Uri.dll
wwwroot/_framework/System.ComponentModel.Annotations.dll.gz
wwwroot/_framework/Microsoft.Extensions.Localization.Abstractions.dll.gz
wwwroot/_framework/Havit.Blazor.Components.Web.dll.gz
wwwroot/_framework/System.Runtime.Serialization.Primitives.dll.br
wwwroot/_framework/System.Text.Encoding.Extensions.dll.br
wwwroot/_framework/System.Text.Encoding.Extensions.dll
wwwroot/_framework/Microsoft.Extensions.DependencyInjection.dll.br
wwwroot/_framework/Microsoft.AspNetCore.Components.WebAssembly.dll.gz
wwwroot/_framework/Microsoft.AspNetCore.Authorization.dll.gz
wwwroot/_framework/System.ComponentModel.dll.br
wwwroot/_framework/Microsoft.JSInterop.dll.br

Error:

enter image description here

enter image description here

Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    private static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Error))
            .ConfigureLogging((hostingContext, logging) =>
            {
                logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                logging.AddConsole();
                logging.AddDebug();
                logging.AddEventSourceLogger();
            }).Build();
}

Startup.cs

public class Startup
{
    private readonly IConfigurationRoot _configuration;

    private readonly IWebHostEnvironment _env;

    public Startup(IWebHostEnvironment env)
    {
        _env = env;

        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", true, true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
            .AddJsonFile("secureHeaderSettings.json", true, true)
            .AddEnvironmentVariables();

        _configuration = builder.Build();
    }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {
        foreach (var file in Directory.GetFiles(Path.Join("wwwroot", "_framework")))
        {
            Console.WriteLine(file);
        }

        services.AddCors(options => options.AddPolicy("CorsPolicy", builder => builder
            .WithOrigins(_configuration.GetSection("TrustedSpaUrls").Get<string[]>())
            .AllowAnyHeader()
            .AllowAnyMethod()
            .AllowCredentials()));

        services.AddOptions();

        services.AddLogging();

        services.AddRouting();
        
        services.AddSignalR(c =>
        {
            c.MaximumReceiveMessageSize = 1024 * 1024 * 1024; // 50 mega-bytes
            c.StreamBufferCapacity = 50;
            c.EnableDetailedErrors = true;
        });

        services.AddSingleton<ILiteDatabase>(new LiteDatabase("db.litedb"));
        services.AddSingleton<PlaybackLogic>();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();

            app.UseCors("CorsPolicy");
        }

        app.UseDefaultFiles()
            .UseStaticFiles()
            .UseRouting()
            .UseEndpoints(endpoints =>
            {
                endpoints.MapHub<MessageHub>("/chat");
            });
    }
}

Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build-env
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY . .

# NuGet restore
RUN dotnet restore

WORKDIR "/app/API"

RUN dotnet publish -c Release -o out

WORKDIR "/app/UI"

RUN dotnet publish -c Release -o out

RUN cp -rpf /app/UI/out/wwwroot /app/API/out

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine

WORKDIR /app
COPY --from=build-env "/app/API/out" .
ENTRYPOINT ["dotnet", "API.dll"]

Repository


Solution

  • I found the solution. The reason dotnet was refusing to serve the .dll files needed in Blazor was that they have an unknown ContentType. See this

    Replacing this:

    app.UseDefaultFiles()
    .UseStaticFiles()
    .UseRouting()
    .UseEndpoints(endpoints => { endpoints.MapHub<MessageHub>("/chat"); });
    

    With this:

    app.UseDefaultFiles()
    .UseStaticFiles(new StaticFileOptions
    {
        ServeUnknownFileTypes = true
    })
    .UseRouting()
    .UseEndpoints(endpoints => { endpoints.MapHub<MessageHub>("/chat"); });
    

    Fixed the problem