Skip to content

Reporting a weird error with .NET 7 and changing hostingContext.HostingEnvironment.ApplicationName #2123

@VictorioBerra

Description

@VictorioBerra

Describe the bug

dotnet/aspnetcore#45022 (comment)

I updated one of my projects to .NET 7 and started getting the following error:

Message: 
System.IO.FileNotFoundException : Could not load file or assembly 'My Awesome App, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

  Stack Trace: 
RuntimeAssembly.<InternalLoad>g____PInvoke|47_0(NativeAssemblyNameParts* pAssemblyNameParts, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Int32 throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly)
RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
Assembly.Load(AssemblyName assemblyRef)
ApplicationPartManager.GetApplicationPartAssemblies(String entryAssemblyName)
ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName)
MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services, IWebHostEnvironment environment)
MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
IServiceCollectionExtensions.AddApiExplorerServices(IServiceCollection services)
IServiceCollectionExtensions.AddVersionedApiExplorer(IServiceCollection services)
Startup.ConfigureServices(IServiceCollection services) line 38
<7 more frames...>
WebApplicationFactory`1.CreateHost(IHostBuilder builder)
WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
WebApplicationFactory`1.EnsureServer()
WebApplicationFactory`1.CreateDefaultClient(DelegatingHandler[] handlers)
WebApplicationFactory`1.CreateDefaultClient(Uri baseAddress, DelegatingHandler[] handlers)
WebApplicationFactory`1.CreateClient(WebApplicationFactoryClientOptions options)
WebApplicationFactory`1.CreateClient()
MyCoolAppControllerTest.ctor(ITestOutputHelper testOutputHelper) line 22
InvokeStub_MyCoolAppControllerTest.ctor(Object, Object, IntPtr*)
ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

The error went away when I commented out the following line:

https://github.com/Dotnet-Boxed/Templates/blob/main/Source/ApiTemplate/Source/ApiTemplate/Program.cs#L59C21-L59C70

I believe the error is because the Product name does not remotely match the assembly name.

Why do we set this? Can we remove it? Should we do this another way?

Steps to reproduce

  1. Create API from Boxed Template using a --title that does not match the app name
  2. Update everything to .net 7
  3. Get error

Expected behaviour

App does not error

Template

API

.NET Boxed Version

Latest

Visual Studio Version

VS22

.NET Version

.NET 7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssues describing a bug or pull requests fixing a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions