I'm developing a WPF application and I would like to add XAML Islands
to be able to use windows 10 controls in my app.
Following this tutorial I added the Microsoft.Toolkit.Wpf.UI.XamlHost
project via Nuget Package Manager. It also installed it's dependencies, like Microsoft.Windows.SDK.Contracts (10.0.18362.2005)
, which has a dependency to System.Runtime.WindowsRuntime >= 4.6.0
. When I run the project, the following compilation error appeared:
Multiple assemblies with equivalent identity have been imported:
'C:\Users\*[path to my project]*\packages\System.Runtime.WindowsRuntime.4.6.0\ref\netstandard2.0\System.Runtime.WindowsRuntime.dll'
and
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll'.
Remove one of the duplicate references.
Clear error message, the XamlHost installed it's dependencies (it modified the app.config
and packages.config
files - the exact rows are posted below) and I also have a WindowsRuntime.dll added by default in MyProject.csproj
file the following way:
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
So I left the dependencies currently installed with XamlHost and removed the default one, what I posted above. Then, when I compiled it threw an error popup that: This application has failed to start because the application configuration is incorrect.
I also tried to remove the other import, which was added when I installed the XamlHost project:
So, removed from the app.config
the following lines:
<dependentAssembly>
<assemblyIdentity name="System.Runtime.WindowsRuntime" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6.0.0" />
</dependentAssembly>
and from packages.config
:
<package id="System.Runtime.WindowsRuntime" version="4.6.0" targetFramework="net471" />
But it threw the same popup, that the project configuration is incorrect.
Also updates to the latest Visual studio (I'm using vs2019 Community), updated to the latest windows SDK, and to the latest .NET Framework.
So, couple of questions:
MyProject.csproj
file is added from the packages
folder, except this WindowRuntime
, which is from Program Files (path above), why is that not referenced from the packages
folder? (Also tried to change it's version to 4.6.0, nothing. Tried to replace the import path and set it to the packages folder, nothing. If I remove it, doesn't even compile the project).WindowsRuntime.dll
in Program Files
what is that .NetCore\v4.5\
, however the latest .NetCore is 3.1? And it contains a WindowsRuntime.dll
version 4.0.0, why?What am I doing wrong?
From the docs:
Using XAML Islands to host WinRT XAML controls is supported only in WPF and Windows Forms apps that target .NET Core 3.x. XAML Islands are not supported in apps that target the .NET Framework.
Judging by the format of your project file and the fact that you are still using a packages.config
file, it seems like you are targeting the .NET Framework. This is not supported.