microsoft / Xaml-Islands-Samples

MIT License
101 stars 44 forks source link

Packaged app crashes when trying to run #5

Closed r2d2rigo closed 4 years ago

r2d2rigo commented 4 years ago

Steps:

Application: WPF_XAMLIslands_v1.exe
CoreCLR Version: 4.700.19.57202
.NET Core Version: 3.0.2
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeLoadException: Could not load type 'System.Windows.Threading.DispatcherObject' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at WPF_XAMLIslands_v1.Program.Main()

Specs:

Problem happens too with packages built in Azure DevOps using hosted agent windows-2019.

Generated .msixbundle can be downloaded from https://we.tl/t-tgTUeaNqvK

marb2000 commented 4 years ago

This is a tooling issue. It was sent to VS team to be fixed in some update of VS 2019. Pending resolution.

chanallenk commented 4 years ago

@marb2000 - Can you please follow up on this issue? It's been a couple months and it's still not fixed, even in Visual Studio 2019 v16.5.1. It's one of the biggest roadblocks in publishing my project... Seems like a lot of our XAML Island issues are getting ignored lately..

stevenbrix commented 4 years ago

@marb2000 do you have a tracking issue for this?

It's nice that this doesn't happen for Debug builds, which should let me look at logs and try to figure out exactly what's going. Luckily, I don't have many better things to do in these strange times ;)

stevenbrix commented 4 years ago

This seems to be an integration issue with .NET Native, so I imagine this will be entirely fixed once we move to WinUI3 since we'll be running on .NET 5.

chanallenk commented 4 years ago

@stevenbrix, thanks for looking into it. I assumed it would. It's just .NET 5 and WinUI 3 is still far from public release and I'd like to publish my app sooner. I think an earlier version of VS was still somewhat working so I guess I will have to roll back to that in the interim.

stevenbrix commented 4 years ago

@chanallenk agreed. If you can go back to a previous version of VS that might be best. If you are just building this app on your own, I may have a workaround that works for you. Be forewarned, it's not pretty :)

Add this to your .wapproj:

  <Target Name="_RemoveNetNativeFromProjectOutput" BeforeTargets="_ConvertItems">
    <ItemGroup>
      <_FilteredNonWapProjProjectOutput Remove="@(_FilteredNonWapProjProjectOutput)" Condition="$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith('C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\'))" />
    </ItemGroup>
  </Target>

I had to hardcode the path, I couldn't find any MSBuild property that pointed to it that was set at the proper time. If those files are at that same place on disk for you then that might work.

If you can't find where those are on your disk, when I looked at the binlog it was the property UWPNugetRepo, but when I tried using that like this, it didn't work:

<_FilteredNonWapProjProjectOutput Remove="@(_FilteredNonWapProjProjectOutput)" Condition="$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith('$(UWPNugetRepo)'))" />
stevenbrix commented 4 years ago

Looks like you might be able to get the value of UWPNugetRepo like this:

<UWPNugetRepo Condition="'$(UWPNugetRepo)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'UWPNugetPackages', null, RegistryView.Registry32, RegistryView.Default))</UWPNugetRepo>
chanallenk commented 4 years ago

@stevenbrix unfortunately that did not work. I'm still getting the same error (VS 16.5.4). While I managed to get it to work in an older version of Visual Studio, I had to roll back all the way to 16.3.8, which means also having to roll back my .NET Core projects from 3.1 to 3.0, which is causing other unrelated issues. Do you have any other suggestions?

michalleptuch commented 4 years ago

I have similar issue when I try to run sideloaded app on local machine. I used this tutorial: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands

Application: MyApp.exe
CoreCLR Version: 4.700.20.26901
.NET Core Version: 3.1.5
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Params:

ocalvo commented 4 years ago

I have similar issue when I try to run sideloaded app on local machine. I used this tutorial: https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands

Application: MyApp.exe
CoreCLR Version: 4.700.20.26901
.NET Core Version: 3.1.5
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (0x80131040)
File name: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

Params:

  • Windows 10.0.18363.x/10.0.19041.x
  • Visual Studio 16.6.2
  • .NET Core 3.1
  • WPF app on .NET Core
  • XamlHost packages 6.1.0
  • no WinUI package

We beleive this was fixed in version 6.1.1 of the toolkit. Can you verify?

chanallenk commented 4 years ago

@ocalvo I am able to confirm that this issue no longer occurs with the updated toolkit v6.1.1, .Net Core 3.1, and Visual Studio v16.6.4 using both a small project (the sample), and a large production Windows App. Thank you for the update.

marb2000 commented 4 years ago

Closing the bug given it was fixed in the version 6.1.1