Using MediaCapture from WPF Framework class assembly
I have an existing WPF application that needs to make use of the MediaCapture class. The idea is to put the image management in a class assembly so that the same code can easily be used across multiple applications. There are a couple of examples on how to use UWP controls in .NET Framework but they all assume that the XAML island is in a WPF application, not a class assembly that is being consumed by the application.
The class assembly has NuGet references to Microsoft.Toolkit.UI.XamlHost, Microsoft.Toolkit.Wpf.UI.Controls, Microsoft.Toolkit.Wpf.UI.XamlHost, Microsoft.VCRTForwarders.150, Microsoft.Windows.WinMD, and System.Runtime.WindowsRuntime. The class library builds but at runtime issues an exception saying that it has to have Windows 10 to run.
The class library exposes a class named ImageManager that has pretty generic methods that the consumer will use to get information about the available cameras, their resolutions, do image streaming and to take snapshots. The idea is that the caller just needs to include the ImageManager and that will take care of everything relating to video images for use.
The View's ViewModel class has a property that references ImageManager. When the ViewModel's class constructor is called the ImageManager is created. During the ImageManager's constructor the available cameras are collected (this works) and WindowsXamlManager.InitializeForCurrentThread() is called. This call throws an exception.
System.Exception
HResult=0x8000FFFF
Message=Catastrophic failure
WindowsXamlManager and DesktopWindowXamlSource are supported for apps targeting Windows version 10.0.18226.0 and later. Please check either the application manifest or package manifest and ensure the MaxTestedVersion property is updated.
The code is running on a Windows 10 machine. I've tried all of the fixes for this I can find but nothing helps. Does anyone have any experience with this and suggestions on how to address the problem?