Skip to content

StackOverflowException in Generic Host CreateApplicationBuilder(args) when running dotnet from Windows on WSL filesystem #121475

Closed

Description

@jamendsurewx

Description

I'm trying to run a Generic Host application that's stored on the WSL filesystem, from the Windows environment. I expect it to run like a regular console app, but instead I get a StackOverflowException after a few minutes.

Reproduction Steps

WSL

$ mkdir ~/repro
$ cd ~/repro
$ dotnet new worker

Windows command prompt

C:\>dotnet run --project \\wsl.localhost\Ubuntu-24.04\home\[user]\repro\repro.csproj

Expected behavior

info: repro.Worker[0]
      Worker running at: 11/09/2025 10:13:55 -05:00
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/jamend/repro
info: repro.Worker[0]
      Worker running at: 11/09/2025 10:13:56 -05:00
info: repro.Worker[0]
      Worker running at: 11/09/2025 10:13:57 -05:00
...

Actual behavior

System.StackOverflowException
...
 	[Managed to Native Transition]	
 	System.Private.CoreLib.dll!Interop.Kernel32.GetMessage(int errorCode, nint moduleHandle)	Unknown
 	System.IO.FileSystem.Watcher.dll!System.IO.FileSystemWatcher.Monitor(System.IO.FileSystemWatcher.AsyncReadState state)	Unknown
 	System.IO.FileSystem.Watcher.dll!System.IO.FileSystemWatcher.StartRaisingEvents()	Unknown
 	Microsoft.Extensions.FileProviders.Physical.dll!Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()	Unknown
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.OnChangeTokenFired()	Unknown
 	System.Private.CoreLib.dll!System.Threading.CancellationTokenSource.Register(System.Delegate callback, object stateForCallback, System.Threading.SynchronizationContext syncContext, System.Threading.ExecutionContext executionContext)	Unknown
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Internal.ChangeCallbackRegistrar.UnsafeRegisterChangeCallback<System.__Canon>(System.Action<object> callback, object state, System.Threading.CancellationToken token, System.Action<System.__Canon> onFailure, System.__Canon onFailureState)	Unknown
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.Action>.RegisterChangeTokenCallback(Microsoft.Extensions.Primitives.IChangeToken token)	Unknown
 	Microsoft.Extensions.Primitives.dll!Microsoft.Extensions.Primitives.ChangeToken.ChangeTokenRegistration<System.__Canon>.OnChangeTokenFired()	Unknown
 	[The 4 frame(s) above this were repeated 3223 times]	
...
   at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RegisterChangeTokenCallback(Microsoft.Extensions.Primitives.IChangeToken)
   at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnChangeTokenFired()
   at System.Threading.CancellationTokenSource.Invoke(System.Delegate, System.Object, System.Threading.CancellationTokenSource)
   at System.Threading.CancellationTokenSource.Register(System.Delegate, System.Object, System.Threading.SynchronizationContext, System.Threading.ExecutionContext)
   at System.Threading.CancellationToken.Register(System.Delegate, System.Object, Boolean, Boolean)
   at System.Threading.CancellationToken.UnsafeRegister(System.Action`1<System.Object>, System.Object)
   at Microsoft.Extensions.Internal.ChangeCallbackRegistrar.UnsafeRegisterChangeCallback[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Action`1<System.Object>, System.Object, System.Threading.CancellationToken, System.Action`1<System.__Canon>, System.__Canon)
   at Microsoft.Extensions.Primitives.CancellationChangeToken.RegisterChangeCallback(System.Action`1<System.Object>, System.Object)
   at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RegisterChangeTokenCallback(Microsoft.Extensions.Primitives.IChangeToken)
   at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnChangeTokenFired()
   at System.Threading.CancellationTokenSource.Invoke(System.Delegate, System.Object, System.Threading.CancellationTokenSource)
   at System.Threading.CancellationTokenSource.Register(System.Delegate, System.Object, System.Threading.SynchronizationContext, System.Threading.ExecutionContext)
   at System.Threading.CancellationToken.Register(System.Delegate, System.Object, Boolean, Boolean)
   at System.Threading.CancellationToken.UnsafeRegister(System.Action`1<System.Object>, System.Object)
   at Microsoft.Extensions.Internal.ChangeCallbackRegistrar.UnsafeRegisterChangeCallback[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Action`1<System.Object>, System.Object, System.Threading.CancellationToken, System.Action`1<System.__Canon>, System.__Canon)
   at Microsoft.Extensions.Primitives.CancellationChangeToken.RegisterChangeCallback(System.Action`1<System.Object>, System.Object)
   at Microsoft.Extensions.Primitives.ChangeToken+ChangeTokenRegistration`1[[System.__Canon, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].RegisterChangeTokenCallback(Microsoft.Extensions.Primitives.IChangeToken)
   at Microsoft.Extensions.Primitives.ChangeToken.OnChange(System.Func`1<Microsoft.Extensions.Primitives.IChangeToken>, System.Action)
   at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(Microsoft.Extensions.Configuration.FileConfigurationSource)
   at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(Microsoft.Extensions.Configuration.IConfigurationBuilder)
   at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(Microsoft.Extensions.Configuration.IConfigurationSource)
   at Microsoft.Extensions.Configuration.ConfigurationManager.Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(Microsoft.Extensions.Configuration.IConfigurationSource)
   at Microsoft.Extensions.Configuration.JsonConfigurationExtensions.AddJsonFile(Microsoft.Extensions.Configuration.IConfigurationBuilder, System.String, Boolean, Boolean)
   at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.ApplyDefaultAppConfiguration(Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Configuration.IConfigurationBuilder, System.String[])
   at Microsoft.Extensions.Hosting.HostApplicationBuilder..ctor(Microsoft.Extensions.Hosting.HostApplicationBuilderSettings)
   at Microsoft.Extensions.Hosting.Host.CreateApplicationBuilder(System.String[])
   at Program.<Main>$(System.String[])

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Activity

  1. added
    untriaged
    on Nov 9, 2025
  2. added
    needs-area-label
    on Nov 9, 2025
  3. MihuBot commented on Nov 9, 2025

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. added and removed
    needs-area-label
    on Nov 9, 2025
  5. added and removed
    untriaged
    on Jan 29, 2026
  6. added this to the 11.0.0 milestone on Jan 29, 2026
  7. cincuranet commented on Jan 29, 2026

    @cincuranet
    Contributor

    Triage: Might be same root cause as #113855, but this is slightly different: WSL vs. systemd.

  8. added a commit that references this issue on Jul 21, 2026
    0cf0d0a
  9. locked and limited conversation to collaborators on Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions