Skip to content

.NET 10, 9, 8, 7, osx-arm64: AccessViolationException in a single-file compressed app #123324

Closed

Description

@nref

Description

On Apple Silicon, my single-file app with compression enabled crashes ~90% of the time with AccessViolationException. The app simply spawns two child processes concurrently. The exact stack trace varies, which is typical of memory corruption.

Reproduction Steps

repro.zip

csproj:

  <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>net10.0</TargetFramework>
      <RuntimeIdentifier>osx-arm64</RuntimeIdentifier>
      <ImplicitUsings>enable</ImplicitUsings>
      <SelfContained>true</SelfContained>
      <PublishSingleFile>true</PublishSingleFile>
      <EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
    </PropertyGroup>
  </Project>

Program.cs:

  using System.Diagnostics;

  var tasks = Enumerable.Range(0, 2)
      .Select(i => Task.Run(async () =>
      {
          var psi = new ProcessStartInfo
          {
              FileName = "/bin/echo",
              Arguments = "hello!",
          };
          using var process = Process.Start(psi)!;
          await process.WaitForExitAsync();
      }));

  await Task.WhenAll(tasks);
  dotnet publish -c Release
  ./bin/Release/net10.0/osx-arm64/publish/Repro
➜  repro git:(main) ✗ ./bin/Release/net10.0/osx-arm64/publish/Repro
hello!
hello!
➜  repro git:(main) ✗ ./bin/Release/net10.0/osx-arm64/publish/Repro
Fatal error.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Span`1[[System.Char, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(Void*, Int32)
   at System.Diagnostics.Process.GetNextArgument(System.String, Int32 ByRef)
   at System.Diagnostics.Process.ParseArgumentsIntoList(System.String, System.Collections.Generic.List`1<System.String>)
   at System.Diagnostics.Process.ParseArgv(System.Diagnostics.ProcessStartInfo, System.String, Boolean)
   at System.Diagnostics.Process.StartCore(System.Diagnostics.ProcessStartInfo)
   at System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
   at Program+<>c+<<<Main>$>b__0_1>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Program+<>c+<<<Main>$>b__0_1>d, Repro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Program+<>c+<<<Main>$>b__0_1>d, Repro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
   at Program+<>c.<<Main>$>b__0_1()
   at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
hello!
[1]    24480 abort      ./bin/Release/net10.0/osx-arm64/publish/Repro
➜  repro git:(main) ✗ ./bin/Release/net10.0/osx-arm64/publish/Repro
Fatal error.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.ArgumentNullException.ThrowIfNull(System.Object, System.String)
   at System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
   at Program+<>c+<<<Main>$>b__0_1>d.MoveNext()
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Program+<>c+<<<Main>$>b__0_1>d, Repro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Program+<>c+<<<Main>$>b__0_1>d, Repro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
   at Program+<>c.<<Main>$>b__0_1()
   at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
[1]    24498 abort      ./bin/Release/net10.0/osx-arm64/publish/Repro
hello!

Expected behavior

Process completes without error.

Actual behavior

Crashes with AccessViolationException: Attempted to read or write protected memory.

Regression?

Reproduces on .NET 7, 8, 9, and 10, with varying failure rates. .NET 6 shows "bus error" 100% of the time.

Framework Failures (out of 100 runs) Failure Rate
net10.0 90 90%
net9.0 94 94%
net8.0 89 89%
net7.0 93 93%
net6.0 100 100%

Known Workarounds

  • Set EnableCompressionInSingleFile=false.
  • Putting a Task.Delay at process start reduces but does not eliminate the failure rate.
Image

Configuration

  • macOS 15.7.1
  • Apple M4 Max (ARM64)
  • SDK 10.0.101 (/usr/local/share/dotnet/sdk)
  • Runtime: Microsoft.NETCore.App 10.0.1

Other information

Likely related to:

Those issues report ~5-9% failure rates. This minimal repro has a ~90% failure rate, which may help isolate the root cause.

Activity

  1. added
    untriaged
    on Jan 18, 2026
  2. added
    needs-area-label
    on Jan 18, 2026
  3. added and removed
    needs-area-label
    on Jan 18, 2026
  4. adamsitnik commented on Jan 19, 2026

    @adamsitnik
    Member

    I am currently working on designing new Process API. I've tried to reproduce the problem in adamsitnik/ProcessPlayground#104 using both old and new APIs, but I've failed.

    git clone https://github.com/adamsitnik/ProcessPlayground.git --branch copilot/add-avrepro-console-app avrepro
    cd avrepro
    dotnet publish AVRepro/AVRepro.csproj -c Release -r osx-arm64
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro

    I'll try to get an access to some arm64 macOS hardware.

  5. nref commented on Jan 19, 2026

    @nref
    Author

    Thanks for the follow up, Adam. I will keep ProcessPlayground in mind for future use. In my case, I'm using Playwright and can't change its direct use of Process

  6. adamsitnik commented on Jan 19, 2026

    @adamsitnik
    Member

    Thanks for the follow up, Adam. I will keep ProcessPlayground in mind for future use. In my case, I'm using Playwright and can't change its direct use of Process

    @nref Is there any chance you could try to run my repro?

    git clone https://github.com/adamsitnik/ProcessPlayground.git --branch copilot/add-avrepro-console-app avrepro
    cd avrepro
    dotnet publish AVRepro/AVRepro.csproj -c Release -r osx-arm64
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro --newAPI
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro --newAPI
    ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro --newAPI
  7. nref commented on Jan 19, 2026

    @nref
    Author

    Hi Adam, certainly. The crash still happens, even with newAPI.

    ➜  avrepro git:(copilot/add-avrepro-console-app) ✗ ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro
    hello!
    hello!
    hello!
    hello!
    Fatal error.
    System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       at System.MarshalByRefObject..ctor()
       at System.Diagnostics.Process..ctor()
       at System.Diagnostics.Process.Start(System.Diagnostics.ProcessStartInfo)
       at Program+<>c+<<<Main>$>b__0_1>d.MoveNext()
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Program+<>c+<<<Main>$>b__0_1>d, AVRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Program+<>c+<<<Main>$>b__0_1>d, AVRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_1>d ByRef)
       at Program+<>c.<<Main>$>b__0_1()
       at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
       at System.Threading.Thread.StartCallback()
    [1]    50262 abort      ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro
    hello!
    ➜  avrepro git:(copilot/add-avrepro-console-app) ✗ ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro --newAPI
    Fatal error.
    System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
       at System.MemoryExtensions.AsSpan(System.String)
       at System.TBA.UnixHelpers.AllocateNullTerminatedUtf8String(System.String)
       at Microsoft.Win32.SafeHandles.SafeChildProcessHandle.StartProcessInternal(System.String, System.String[], System.String[], System.TBA.ProcessStartOptions, Int32, Int32, Int32)
       at Microsoft.Win32.SafeHandles.SafeChildProcessHandle.StartCore(System.TBA.ProcessStartOptions, Microsoft.Win32.SafeHandles.SafeFileHandle, Microsoft.Win32.SafeHandles.SafeFileHandle, Microsoft.Win32.SafeHandles.SafeFileHandle)
       at Microsoft.Win32.SafeHandles.SafeChildProcessHandle.Start(System.TBA.ProcessStartOptions, Microsoft.Win32.SafeHandles.SafeFileHandle, Microsoft.Win32.SafeHandles.SafeFileHandle, Microsoft.Win32.SafeHandles.SafeFileHandle)
       at System.TBA.ChildProcess+<ExecuteAsync>d__1.MoveNext()
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.TBA.ChildProcess+<ExecuteAsync>d__1, Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<ExecuteAsync>d__1 ByRef)
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[[System.Int32, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Start[[System.TBA.ChildProcess+<ExecuteAsync>d__1, Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<ExecuteAsync>d__1 ByRef)
       at System.TBA.ChildProcess.ExecuteAsync(System.TBA.ProcessStartOptions, System.Threading.CancellationToken)
       at Program+<>c+<<<Main>$>b__0_3>d.MoveNext()
       at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[Program+<>c+<<<Main>$>b__0_3>d, AVRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_3>d ByRef)
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[Program+<>c+<<<Main>$>b__0_3>d, AVRepro, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](<<<Main>$>b__0_3>d ByRef)
       at Program+<>c.<<Main>$>b__0_3()
       at System.Threading.Tasks.Task`1[[System.__Canon, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].InnerInvoke()
       at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread, System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
       at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef, System.Threading.Thread)
       at System.Threading.ThreadPoolWorkQueue.Dispatch()
       at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()
       at System.Threading.Thread.StartCallback()
    [1]    50289 abort      ./AVRepro/bin/Release/net10.0/osx-arm64/publish/AVRepro --newAPI
    
  8. adamsitnik commented on Jan 19, 2026

    @adamsitnik
    Member

    @nref Thanks a lot!

  9. nref commented on Jan 19, 2026

    @nref
    Author

    Thank you!

  10. added this to the 11.0.0 milestone on Apr 14, 2026
  11. removed
    untriaged
    on Apr 14, 2026
  12. added 2 commits that reference this issue on Apr 24, 2026
    a6a619c
    de6098b
  13. elinor-fung commented on Apr 29, 2026

    @elinor-fung
    Member

    @nref thanks for the pared down repro - super helpful.

  14. adamscybot commented on Apr 30, 2026

    @adamscybot

    Just a note that this seems fairly likely to solve #112167

  15. locked and limited conversation to collaborators on May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions