Fehlermeldung "PE-Abbild enthält keine verwalteten Metadaten"

Nach einem NuGet-Update von mehreren Referenzen in einer Visual-Studio-2022-Solution trat plötzlich beim Start meiner Anwendung mit ASP.NET Core .NET 7 folgende Exception auf:

Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.CompilationFailedException: ‚One or more compilation failures occurred:
error CS0009: Metadatendatei „C:\MyWebApp\bin\Release\net7.0\krbcc64.dll“ konnte nicht geöffnet werden: PE-Abbild enthält keine verwalteten Metadaten.
error CS0009: Metadatendatei „C:\MyWebApp\bin\Release\net7.0\krb5_64.dll“ konnte nicht geöffnet werden: PE-Abbild enthält keine verwalteten Metadaten.
error CS0009: Metadatendatei „C:\MyWebApp\bin\Release\net7.0\k5sprt64.dll“ konnte nicht geöffnet werden: PE-Abbild enthält keine verwalteten Metadaten.
error CS0009: Metadatendatei „C:\MyWebApp\bin\Release\net7.0\gssapi64.dll“ konnte nicht geöffnet werden: PE-Abbild enthält keine verwalteten Metadaten.
error CS0009: Metadatendatei „C:\MyWebApp\bin\Release\net7.0\comerr64.dll“ konnte nicht geöffnet werden: PE-Abbild enthält keine verwalteten Metadaten.‘

Stack-Trace war:

at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.CompileAndEmit(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.OnCacheMiss(String normalizedPath)
— End of stack trace from previous location —
at Microsoft.AspNetCore.Mvc.Razor.Compilation.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|22_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
— End of stack trace from previous location —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
— End of stack trace from previous location —
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)

Nachdem ich dutzende NuGet-Pakete wieder deinstalliert hatte, habe ich den Übeltäter erwischt:

MySql.Data

In Version 8.0.31 hat es noch funktioniert. In Version 8.0.32 kommt obiger Fehler.

Ich habe jetzt als Lösung/Workaround die Version 8.0.31 installiert und dann eingefroren als Version in der CSPROJ-Datei

<PackageReference Include="MySql.Data" Version="[8.0.31]" />

Das verhindert dann ein automatisches Update. Fürs Erste ausreichend.