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

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

Open
VictorioBerra opened this issue Jul 20, 2023 · 0 comments
Labels
bug Issues describing a bug or pull requests fixing a bug.

Comments

@VictorioBerra
Copy link
Collaborator

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

@VictorioBerra VictorioBerra added the bug Issues describing a bug or pull requests fixing a bug. label Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug or pull requests fixing a bug.
Projects
None yet
Development

No branches or pull requests

1 participant