Reputation: 1221
I want to use the OCR component of UWP in an WPF C# app.This is done by using a C# class library in other projects. On build I get the following error shown below. How can I get this to compile?
Error 1 Problem generating manifest. Could not load file or assembly '{MyAppPath}\Windows.winmd' or one of its dependencies. Attempt to load a program with an incorrect format.
The picture shows the references:
The files are:
System.Runtime.WindowsRuntime: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
System.Runtime.InteropServices.WindowsRuntime: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\Facades\System.Runtime.InteropServices.WindowsRuntime.dll
Windows: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
The Code I want to use (not in a finsished state, I just want it to compile)
using System;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;
using Windows.Storage;
namespace tegBase
{
public class Scan
{
public static async void OcrAusfuehren()
{
var fileName = @"C:\a.jpg";
StorageFile file = await StorageFile.GetFileFromPathAsync(fileName);
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
SoftwareBitmap b;
b = await decoder.GetSoftwareBitmapAsync();
OcrEngine ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages();
var s = await ocrEngine.RecognizeAsync(b);
Windows.Media.Ocr.OcrResult c = s;
Console.WriteLine(c.Text);
}
}
}
Update:
I tried to reproduce the error on another PC, there however, the UnionMetadata folder is empty. So I took the winmd from 10.0.16299.0, but it lead to the same result.
I also tried changing the target framework from .net 4.5.1 to 4.6.1, which also did not solve the problem. On a sidenote: changing it to 4.7.1 was not possible, as VS said it was not installed. Installing 4.7.1 was also not possible, with the installer message beeing: Higher Version already installed.
Upvotes: 2
Views: 375
Reputation: 906
You need to download the UWP software development kit (SDK) and migrate the package to package references. This must be done in order to use all the UWP libraries within a WPF/WinForms/Console application. Please visit this website for a step-by-step tutorial: https://www.thomasclaudiushuber.com/2019/04/26/calling-windows-10-apis-from-your-wpf-application/
Upvotes: 0