AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
26.05k stars 2.25k forks source link

Visual Studio Designer fail to render when Platform target is x86 #5209

Closed alan0428a closed 7 months ago

alan0428a commented 3 years ago

Hello team,

I've created the "Avalonia MVVM Application" template project from visual studio. And I've updated Avalonia packages to v0.10.0-rc1. Then I set the project platform target to x86. The designer renders correctly for about 1 ~ 2 seconds then shows "Process Exited" without properly render.

If I switch platform target back to Any CPU, then everything works fine. Is this a bug?

image

Steps to reproduce the behavior:

  1. Create MVVM template using visual studio
  2. Update all packages to v0.10.0-rc1
  3. Set project platform target to x86
  4. See MainWindow.axaml

Visual Studio Version: Microsoft Visual Studio Professional 2019 Version 16.8.3 OS: Windows 10 Enterprise Runtime: netcoreapp3.1

Below are the error output from Avalonia Diagnostics

15:47:18.603 [Debug]  Build started
15:47:18.608 [Debug]  Build started
15:47:18.608 [Debug]  Setting pause state to True
15:47:18.608 [Verbose]  Started PreviewerProcess.Stop()
15:47:18.608 [Information]  Stopping previewer process
15:47:18.608 [Verbose]  Finished PreviewerProcess.Stop()
15:47:19.555 [Debug]  Build finished
15:47:19.557 [Debug]  Build finished
15:47:19.557 [Debug]  Setting pause state to False
15:47:19.557 [Verbose]  Started AvaloniaDesigner.StartProcessAsync()
15:47:19.557 [Verbose]  Started AvaloniaDesigner.CreateCompletionMetadataAsync() for "C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll"
15:47:19.557 [Verbose]  Started PreviewerProcess.StartAsync()
15:47:19.558 [Information]  Starting previewer process for '"C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll"'
15:47:19.558 [Debug]  > dotnet.exe "exec --runtimeconfig \"C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.runtimeconfig.json\" --depsfile \"C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.deps.json\" \"C:\Users\alanyu\.nuget\packages\avalonia\0.10.0-rc1\build\\..\tools\netcoreapp2.0\designer\Avalonia.Designer.HostApp.dll\" --transport tcp-bson://127.0.0.1:57580/ \"C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll\""
15:47:20.062 [Information] 11168 Started previewer process for '"C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll"'. Waiting for connection to be initialized.
15:47:20.672 [Error] 11168 <= "Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Avalonia.Base, Version=0.10.0.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)"
15:47:20.685 [Error] 11168 <= "File name: 'Avalonia.Base, Version=0.10.0.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b'"
15:47:20.686 [Error] 11168 <= "   at Avalonia.Designer.HostApp.Program.Main(String[] args)"
15:47:21.349 [Verbose]  Finished AvaloniaDesigner.CreateCompletionMetadataAsync() took 00:00:01.7920818 for "C:\Users\alanyu\source\repos\avax86\AvaloniaApplication\AvaloniaApplication\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll"
15:47:21.349 [Verbose]  Finished AvaloniaDesigner.CreateCompletionMetadataAsync()
15:47:22.196 [Information]  Process exited while waiting for connection to be initialized.
15:47:22.199 [Debug]  Process.StartAsync exited with error
System.ApplicationException: The previewer process exited unexpectedly with code -532462766.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at AvaloniaVS.Services.PreviewerProcess.<StartAsync>d__30.MoveNext() in D:\a\1\s\AvaloniaVS\Services\PreviewerProcess.cs:line 232
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at AvaloniaVS.Views.AvaloniaDesigner.<StartProcessAsync>d__55.MoveNext() in D:\a\1\s\AvaloniaVS\Views\AvaloniaDesigner.xaml.cs:line 441
15:47:22.199 [Verbose]  Finished AvaloniaDesigner.StartProcessAsync()
15:47:22.197 [Information]  Process exited
15:47:22.199 [Verbose]  Started PreviewerProcess.Stop()
15:47:22.199 [Information]  Stopping previewer process
15:47:22.200 [Verbose]  Finished PreviewerProcess.Stop()
kekekeks commented 3 years ago

Try deleting all of your bin/obj directories, it seems that an unsigned copy of some dll is still there

alan0428a commented 3 years ago

Try deleting all of your bin/obj directories, it seems that an unsigned copy of some dll is still there

I've deleted the folders, but the issue still exists.

rstm-sf commented 3 years ago

It seems to me that the problem is here

\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll

Then it is related to this issue https://github.com/AvaloniaUI/AvaloniaVS/issues/190

As far as I remember, when we specify the platform, this name is added to the path in the form of a folder. One temporary solution is to specify in PropertyGroup csproj

<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>

or like

<OutputPath>bin\$(Configuration\$(TargetFramework)\$(MSBuildProjectName)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
alan0428a commented 3 years ago

It seems to me that the problem is here

\bin\Debug\netcoreapp3.1\AvaloniaApplication.dll

Then it is related to this issue AvaloniaUI/AvaloniaVS#190

As far as I remember, when we specify the platform, this name is added to the path in the form of a folder. One temporary solution is to specify in PropertyGroup csproj

<AppendPlatformToOutputPath>false</AppendPlatformToOutputPath>

or like

<OutputPath>bin\$(Configuration\$(TargetFramework)\$(MSBuildProjectName)</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

Well, my original build output path doesn't append the platform. And I also follow your steps, but it doesn't work.

esonhon commented 3 years ago

Same situation here, worked for about 2 days, have no solution.

esonhon commented 3 years ago

Found some clue after 2 days work. The avalonia dll Avalonia.DesignerSupport.dll we got from nuget is targeted for AnyCpu, according to my test, only x86 targeted application can load my x86 assembly(myapp.dll) using Assembly.LoadFile(), when previewer routine Avalonia.DesignerSupport.dll try to load the dll, System.IO.FileLoadException raised.

romarro commented 7 months ago

Is there any solution to this issue? I am having also this issue regarding an x86 app.

maxkatz6 commented 7 months ago

There are no current plans to support this scenario. Not to mention "Target" and "PlatformTarget" properties by itself are deprecated and should not be used for .net core apps. For any modern app Runtime Identifier should be used.