Reference File Not Found Issues in .Net 8

I have a WPF application that references the Mahapps.Metro nuget package. When migrating from .Net Framework 4.8 to .Net 8.0 I run into this issue with a dependency of the package Microsoft.Xaml.Behaviors.Wpf (From ControlzEx Dependency). The software is unable to find the dll in runtime. I tried several workarounds but they all failed.

I am running the latest version of Oxygene 12.0.0.2909 in Visual Studio 2022

In the end, I was able to reproduce this in a simple WPF project, only doing a few steps after creating the template.

Steps to reproduce:

  1. Create new project “Windows WPF Application (.NET Core)”
  2. Add the “Mahapps.Metro” nuget package (Version 2.4.10)
  3. Add a Mahapps control to the Window.xaml such as DateTimePicker
  4. Run and observe

I attached this short example if needed.
WPFApplication1.zip (2.0 MB)

The error message is an inner exception to a XAML error seen at runtime:


FileNotFoundException: Could not load file or assembly 'Microsoft.Xaml.Behaviors, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Any help or advice is much appreciated. Thank you.

Can you try adding an explicit reference to Microsoft.Xaml.Behaviors.Wpf, and setting it to copy local?

I tried that and couldn’t get it to work. I attempted it again using the example project and got the same strange behavior I failed to mention in the original write up. There are two strange things that occur:

  1. The reference doesn’t appear in the Solution Explorer but it’s added to the project file. This forces me to configure it by editing that file.

  2. The build appears to ignore the reference. Here’s a snippet of the diagnostic build log where it explicitly says so:

-> Task RemObjects.EBuild.Elements.ElementsResolveReferences started for WPFApplication1.
1>		               -> Target Echoes started.
1>		                  -> Task RemObjects.EBuild.Elements.ElementsResolveEchoesReferencesForTarget started for WPFApplication1, Echoes.
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors.DesignTools' for target 'Echoes' (Echoes .NETCore).
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors' for target 'Echoes' (Echoes .NETCore).
1>		                     Ignoring legacy reference 'System.Text.Json' for target 'Echoes' (Echoes .NETCore).
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors' for target 'Echoes' (Echoes .NETCore).
1>		                     Reference 'Echoes' was resolved to 'C:\Program Files (x86)\RemObjects Software\Elements\References\Echoes\NETCore5.0\Echoes.dll' via XML for target 'Echoes'.
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors.DesignTools' for target 'Echoes' (Echoes .NETCore).
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors' for target 'Echoes' (Echoes .NETCore).
1>		                     Ignoring legacy reference 'System.Text.Json' for target 'Echoes' (Echoes .NETCore).
1>		                     Reference 'ControlzEx' was resolved to 'C:\Users\danan\source\repos\WPFApplication1\packages\ControlzEx.4.4.0\lib\netcoreapp3.1\ControlzEx.dll' via 'HintPath' for target 'Echoes'.
1>		                     Reference 'MahApps.Metro' was resolved to 'C:\Users\danan\source\repos\WPFApplication1\packages\MahApps.Metro.2.4.10\lib\netcoreapp3.1\MahApps.Metro.dll' via 'HintPath' for target 'Echoes'.
1>		                     Ignoring legacy reference 'Microsoft.Xaml.Behaviors' for target 'Echoes' (Echoes .NETCore).
1>		                     -> Task RemObjects.EBuild.Elements.ElementsProcessNuGetReferences started for WPFApplication1, Echoes.

How do you reference this? As a .dll reference or a NuGet Package Reference? Any .dll references that start with System. or Microsoft. are ignored; the appropriate NuGet packages should be referenced instead.

Aha! I was referencing the DLL. So I changed the Nuget references to the newer style. I removed all Nuget references first and re-added Mahapps.Metro, setting it to copy local like so:

<NuGetReference Include="MahApps.Metro:[2.4.10]">
      <Private>True</Private>
    </NuGetReference>

The project now works! No other direct references were required. Although it’s strange that the older Nuget references are the default configuration of the package manager.

In any event, this helps a lot. Now I can continue the migration. Thanks.

Happy to hear!