[WebToolsE2E][ARM64]Failed to run .exe file with error "System.AccessViolationException: Attempted to read or write protected memory" from publish folder after publishing .NET 8.0 project against self-contained with single file
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
**Azure DevOps work item:**
https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2014650
**Testcases Affected**
This issue was found via Exploratory Testing, no test case was affected.
**Platform**
- [x] Windows
- [ ] macOS
- [ ] Linux
**INSTALL STEPS**
1. Clean machine: A clean ARM64 virtual machine
2. Install the latest March Servicing SDK 8.0.203(runtime 8.0.3) from https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-8.0.203-windows-arm64-installer
**Repro Steps**
1. Open command prompt->Create a folder named as "Web01" with command `mkdir Web01`
3. Navigate Web01 folder ->Create ASP.NET Core Web App(Razor Pages) with command `dotnet new razor -f net8.0`
4. Run the project with command `dotnet build`
5. Publish to folder against self-contained with single file with command `dotnet publish -c Release -r win-arm64 --self-contained true -p:PublishSingleFile=true`
6. Double click the .exe file from publish path "...\Web01\bin\Release\net8.0\win-arm64\publish\" when finish running publish command.
> **Note:**
>
> 1. The issue also reproduce from VS with UI.
> 2. The issue only reproduce on NET 8.0, cannot reproduce on Net6.0/7.0
> 3. The issue also reproduce on February servicing SDK 8.0 and April Servicing 8.0, so it is not a regression issue.
> 4. The issue only reproduce on Net 8.0 publish to folder against self-contained with single file, cannot reproduce publish to folder against self-contained.
> 5. This issue cannot reproduce on x64 machines, only reproduce on arm64 machines.
**ACTUAL**
Failed to run .exe file as following

Error messages:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Microsoft.AspNetCore.Mvc.ApplicationModels.AuthorizationApplicationModelProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelProviderContext)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(System.Collections.Generic.IEnumerable`1)
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptorProviderContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.GetChangeToken()
at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(System.Func`1, System.Action`1, System.__Canon)
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(System.Func`1, System.Action)
at Microsoft.AspNetCore.Mvc.Routing.ActionEndpointDataSourceBase.Subscribe()
at Microsoft.AspNetCore.Builder.RazorPagesEndpointRouteBuilderExtensions.GetOrCreateDataSource(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)
at Microsoft.AspNetCore.Builder.RazorPagesEndpointRouteBuilderExtensions.MapRazorPages(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder)
at Program.$(System.String[])
**EXPECTED**
.exe file should run successfully.

### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.