Single file exe + razor nuget breaks routing in asp.net core application
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Describe the bug
In any asp.net core project using the new .NET 5 single file exe publish command, routing is broken due to the use of Assembly.CodeBase. This impacts routing calls such as:
- `IEndpointRouteBuilder.MapControllerRoute`
- `IApplicationBuilder.UseEndPoints` and then calling either `MapRazorPages` or `MapControllers`
There are probably others.
### To Reproduce
See attached zip at bottom of thread. This appears to be a problem of adding some razor functionality to the service collection.
Run the published exe with a --urls parameter and then open your browser and attempt to hit the weather forecast end point.
### Exceptions (if any)
Use of Assembly.CodeBase throws not supported exception and application crashes.
### Further technical details
- ASP.NET Core version 5.0
- Does not reproduce in debugger. You must use dotnet publish command and turn on the single file option with `/p:PublishSingleFile=$publishSingleFile`
For servers obviously this can be worked around, just turn off the single file option. For client software that uses a web browser UI however this is unfortunate as the single file exe vastly reduces the number of files the client has to mess with to get the application deployed.
Contributor guide
Assessment
This issue has not been assessed yet.