Repository navigation
Previewer process crashes because of dependency issue #197
Description
Describe the bug
Similar to AvaloniaUI/AvaloniaVS#639, when using the Visual Studio Extension Avalonia Previewer inside a project targeting net9.0, the previewer container process crashes during initialization with a TargetInvocationException wrapping a FileNotFoundException for System.Diagnostics.DiagnosticSource, Version=9.0.0.0.
This happens even though the project compiled successfully and runs correctly, because of transitive package dependency promotion to .NET 10.x layers (specifically matching modern assemblies brought in by components like ReactiveUI.Avalonia and Splat targeting modern frameworks).
I believe this to be caused by a recent update to the extension, since reverting to an older commit does not help resolve the issue. Switching the project to .Net10 changes the error message only slightly, where it will fail to find version 10.0.0.0 instead. No amount of updates/downgrades seems to help, other than the workaround described below.
To Reproduce
Steps to reproduce (not exactly sure and cannot share affected repo):
- Create an Avalonia application targeting net9.0 (Avalonia 11.3.17).
- Add a dependency package or package dependency graph that promotes some Microsoft transitive namespaces to .NET 10 versions (for example, choosing Splat/ReactiveUI integration libraries that pull Microsoft.Extensions.DependencyInjection version 10.0.8 or System.Diagnostics.DiagnosticSource 10.0.3 to resolve package downgrades).
- Attempt to open any .axaml file in Visual Studio with the Avalonia Designer Previewer active.
- The designer fails to load and reports a connection channel failure (because the TcpTransportBase process crashes on sockets telemetry initialization).
What is actually happening?
- In a net9.0 target application, core system libraries (like the socket networking library System.Net.Sockets) contain static assembly bindings pointing directly to System.Diagnostics.DiagnosticSource, Version=9.0.0.0.
- When NuGet pulls version 10.x of System.Diagnostics.DiagnosticSource into the dependencies graph, it copies the 10.x asset into the local output bin directory.
- During shadow-copy setup (ShadowCopyOutputStrategy), the previewer worker loads assemblies from this local directory. The presence of the 10.x DLL interrupts the fallback resolution rules of the .NET 9 host process. Thus, when System.Net.Sockets calls static methods requiring assembly version 9.0.0.0, the loader fails to find/bind the framework-specific 9.x reference, causing SocketsTelemetry static context creation to fail.
Expected behavior
The previewer worker process should load and shadow-copy dependencies while safely honoring host-specific framework resolution bindings when launching within a target framework (such as net9.0).
Workaround:
Declaring assembly references directly in the project with <ExcludeAssets>runtime</ExcludeAssets> attributes resolves the previewer issue but creates differences between build and execution runtime behaviors.
AvaloniaVS plugin version
12.1.2.0
Avalonia version
11.3.17
Visual Studio version
Enterprise 2026 (18.6.2)
Relevant log output
14:22:51.438 [Information] [AvaloniaUI.Previewer.Process.PreviewerProcessFactory] Resolving metadata for 'C:\Users\LZJ05\source\repos\app-persephone\Persephone\Persephone.csproj' (TFM=net9.0)
14:22:51.437 [Information] [PreviewerProcess (#853803)] Process exited while waiting for connection to be initialized.
14:22:51.437 [Information] [PreviewerProcess (#853803)] Process exited: GenericError
14:22:51.437 [Information] [PreviewerProcess (#853803)] Stopping previewer process
14:22:51.460 [Information] [AvaloniaUI.Previewer.Process.Output.ShadowCopyOutputStrategy] Shadow copy reused at 'C:\Users\LZJ05\AppData\Local\AvaloniaUI\com.AvaloniaUI.Net.VisualStudio\Previewer\eldoLEDSTUDIOManager_QC5uTh8YMtv-HveZ' (42 files)
14:22:51.467 [Information] [PreviewerProcess (#853803)] Starting previewer process for target C:\Users\LZJ05\AppData\Local\AvaloniaUI\com.AvaloniaUI.Net.VisualStudio\Previewer\eldoLEDSTUDIOManager_QC5uTh8YMtv-HveZ\eldoLEDSTUDIOManager.dll (ShadowCopy=True, NewHostApp=True)
14:22:51.481 [Information] [PreviewerProcess (#853803)] [7028] Started previewer process for 'C:\Users\LZJ05\AppData\Local\AvaloniaUI\com.AvaloniaUI.Net.VisualStudio\Previewer\eldoLEDSTUDIOManager_QC5uTh8YMtv-HveZ\eldoLEDSTUDIOManager.dll'. Waiting for connection to be initialized.
14:22:51.456 [Information] [AvaloniaUI.VisualStudio.Extension.Services.CpsAssetsPreviewerMetadataService] Resolving extra packages [Avalonia.Headless, Avalonia.Markup.Xaml.Loader] (Avalonia 11.3.17, net9.0)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= ---> System.AggregateException: One or more errors occurred. (Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= File name: 'System.Diagnostics.DiagnosticSource, Version=9.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.SocketsTelemetry..cctor()
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.Socket.ConnectAsync(SocketAsyncEventArgs e, Boolean userSocket, Boolean saeaCancelable)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket, Boolean saeaCancelable)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP, CancellationToken cancellationToken)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Net.Sockets.TcpClient.ConnectAsync(IPAddress address, Int32 port)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at AvaloniaUI.Previewer.Protocol.TcpTransportBase.Connect(IPAddress address, Int32 port)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= --- End of inner exception stack trace ---
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at AvaloniaUI.Previewer.DesignerSupport.EntryPoint.CreateTransport(CommandLineArgs args)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at AvaloniaUI.Previewer.DesignerSupport.EntryPoint.CreateWindowManager(CommandLineArgs args)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at AvaloniaUI.Previewer.DesignerSupport.EntryPoint.SetupPreviewer(String[] cmdline)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at AvaloniaUI.Previewer.DesignerSupport.EntryPoint.Main(String[] cmdline)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= --- End of inner exception stack trace ---
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
14:22:51.743 [Error] [PreviewerProcess (#853803)] [7028] <= at Program.<Main>$(String[] args)
14:22:59.860 [Information] [PreviewerProcess (#853803)] Process exited while waiting for connection to be initialized.
14:22:59.860 [Information] [PreviewerProcess (#853803)] Process exited: GenericError
14:22:59.860 [Information] [PreviewerProcess (#853803)] Stopping previewer processAdditional context
No response
Activity
Luk164 commentedon Jun 10, 2026
Possibly duplicate of #196, though it seems the cause is different here. I am not using the package that is said to be the cause. Also transplanting all my packages to a fresh template keeps working.
Luk164 commentedon Jun 10, 2026
Replacing the extension with 11.12.1.0 fixes the issue
maxkatz6 commentedon Jun 10, 2026
Thanks, I was able to reproduce this issue
maxkatz6 commentedon Jun 10, 2026
@Luk164 you can disable experimental previewer in the Avalonia VS extension settings, on the newer version. It will bring back behavior without downgrading.
Luk164 commentedon Jun 11, 2026
Thanks, that worked. Is it enabled by default? I do not recall turning it on myself.
maxkatz6 commentedon Jun 12, 2026
@Luk164 yes, it is now.
maxkatz6 commentedon Jun 12, 2026
Fix was merged, and will be available in the next VS/VSC extension release
NickBarton commentedon Jun 24, 2026
Disabling experimental previewer in the Avalonia VS extension settings also worked for me.
kelvin-martin commentedon Aug 18, 2026
I have a similar error message: Failed to prepare shadow copy output for project. Project is a WinEXE targeting .Net 9.0 with the following Avalonia packages:
The diagnostic output is similar to what was reported.
Disabled the Experimental Previewer, and the problem was resolved.
mrlacey commentedon Aug 19, 2026
Reopening and disabling the experimental previewer should be a temporary workaround.
This must be fixed in the new previewer.
mrlacey commentedon Sep 24, 2026
To help better manage work across all the different Avalonia repositories we are consolidating some of the issues into a single repository.
This issue is being transferred as part of that consolidation.