0

I have a .NET-wrapper library based on .NET Framework v4.6.1, which invokes UWP OCR API. It contains only one class with one function in it, code is below

public static async Task<string> ExtractText(Stream stream, string language)
        {
            using (IRandomAccessStream uwpStream = new InMemoryRandomAccessStream())
            {
                byte[] input = new byte[stream.Length];
                stream.Read(input, 0, input.Length);
                uwpStream.AsStreamForWrite().Write(input, 0, input.Length);
                uwpStream.AsStreamForWrite().Flush();
                uwpStream.Seek(0);
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(uwpStream);
                SoftwareBitmap bitmap = await decoder.GetSoftwareBitmapAsync();
                OcrEngine engine = OcrEngine.TryCreateFromLanguage(new 
                                              Language(language));
                uwpStream.Dispose();
                if (engine != null)
                {
                    OcrResult result = await engine.RecognizeAsync(bitmap);
                    return result.Text;
                }
                else
                {
                    throw new NullReferenceException("Language is not supported");
                }
            }
        }

Project has links to following UWP libraries: Windows.WinMD, Windows.Foundation.FoundationContract.winmd, Windows.Foundation.UniversalApiContract.winmd. I found their location via object browser in Visual Studio, copied them from their original location to subfolder in my project and then linked them.

My app runs ok on my local machine and UWP OCR Engine works fine.

Then I deploy my library and an application, which uses it, on my virtual machine, which has Windows Server 2012 R2 on it with installed .NET Framework and installed Windows 10 SDK. My program fails during runtime with the exception: Could not find Windows Runtime type "Windows.Graphics.Imaging.SoftwareBitmap"

To solve the problem I tried to reinstall Windows 10 SDK on my virtual server and checked that versions match exact versions on my development machine. It seems like some of the .winmd libraries does not load in runtime.

I expect my program to run successfully on another machine in release mode. It works on development machine fine. However, I am new to UWP, so maybe initial information is not enough to solve the problem, but I'm ready to provide more.

Any help would be appreciated

2
  • You must use Publish when moving any Visual Studio Application to another PC which also installs any dll that are use by the PC. Make sure you use Any PC option. Visual Studio requested the same version of Net to be installed on Target and Deploy PC ot work without doing a publish and then install like commercial software running setup.exe.
    – jdweng
    Jan 14, 2019 at 15:42
  • How can a UWP API run on a non-Windows 10 OS?? Jan 14, 2019 at 19:21

1 Answer 1

0

I was able to make my UWP OCR work on Windows Server 2019 It seems like Windows Server 2012 R2 does not support all the functional of Windows 10 SDK At least my program could not load all the .winmd files required in runtime Migration to Windows Server 2019 makes it work without any problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.