ML.NET: strange runtime error on some machines - c#

I wrote a simple UWP app using the ML.NET framework, and it worked on one of my machines without installing any Nuget packages, without any additional setup etc.
However, on my other machine, after running the application, I get this error:
System.Runtime.InteropServices.COMException: 'Unspecified error
No suitable kernel definition found for op Sub (node Minus675)'
The error happens in this segment of code:
public static async Task<modelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
{
modelModel learningModel = new modelModel();
learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
learningModel.session = new LearningModelSession(learningModel.model); // it breaks here
learningModel.binding = new LearningModelBinding(learningModel.session);
return learningModel;
}
In case anyone should ask - yes I have added my .onnx model in the Assets folder. My configuration is: VS 2017, Windows 10 version 1809, build 17763.194, and I have Windows 10 SDK version 10.0.17763.132. I have tried installing the Visual Studio Tools for AI and ML.NET Templates VS extensions, but it didn't help.

Related

Creating a CosmosDB database locally with C# code throws an Internal Server error

I try to create a database in the local cosmosDB emulator but this fails to work. It throws an exception with the following message:
Response status code does not indicate success: InternalServerError
(500); Substatus: 0; ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc;
Reason: (Unknown server error occurred when processing this request.
ActivityId: 36f6a95d-26d7-4ecd-9c81-f6df220f3cdc,
Microsoft.Azure.Documents.Common/2.14.0,
Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum,
Windows/10.0.19042 cosmos-netstandard-sdk/3.24.1);
This error happens in my project as well as in an simple, empty console app only containing these lines of code:
using Microsoft.Azure.Cosmos;
namespace CosmosDBTest;
class Program
{
public static async Task Main()
{
using var client = new CosmosClient("<A local connection string>");
var response = await client.CreateDatabaseIfNotExistsAsync("test", 500);
var database = response.Database;
await database.CreateContainerIfNotExistsAsync("container1", "id");
}
}
The version of the emulator I use is 2.14.6. The version of the NuGet package is 3.26.1
What is causing this exception and how do I solve this? I has worked with older versions of the emulator in combination of an older version of the NuGet package. But before I downgrade the emulator and/or package, I want to find out if there is a better work around.
I haven't tried the demo application which is offered by the emulator. Funny enough as it is on a tab with the name ".NET" (and another tab .NET core next to it) the ".NET" example is written in the very old version .net core 2.1 which I don't have installed even.
Try resetting the Emulator, this looks like a malfunction on the Emulator itself. The HTTP 500 is coming from the Emulator, the SDK is just surfacing the response.
Reference: https://learn.microsoft.com/azure/cosmos-db/troubleshoot-local-emulator
If you installed a new version of the emulator and are experiencing errors, ensure you reset your data. You can reset your data by right-clicking the Azure Cosmos DB Emulator icon on the system tray, and then clicking Reset Data…. If that does not fix the errors, you can uninstall the emulator and any older versions of the emulator if found, remove C:\Program files\Azure Cosmos DB Emulator directory and reinstall the emulator.
Alternatively if resetting the data doesn't work, navigate to %LOCALAPPDATA%\CosmosDBEmulator location and delete the folder.

How to fix "libtensorflow DllNotFoundException" when I already have the file?

I'm new to C# and I've been researching this error for a long time.
I wanted to use my trained TensorFlow model with Tensorflowsharp in Visual Studio for Mac so I created a .NET console project and installed TensorflowSharp 1.13.0 from nuget.org using the built-in package manager.
However, when I included the following code in Program.cs
using System;
using TensorFlow;
namespace ai
{
class MainClass
{
public static void Main(string[] args)
{
var graph = new TFGraph();
}
}
}
I got this error message:
Unhandled Exception:
System.DllNotFoundException: libtensorflow
at (wrapper managed-to-native) TensorFlow.TFGraph.TF_NewGraph()
at TensorFlow.TFGraph..ctor () [0x00022] in <a8cd6d02fde04a81817b4f25d24a7be9>:0
According to some of the posts that I found, this might states that libtensorflow.dylib is not in bin/Debug/ directory, but when I looked into it I found the file inside.
What am I doing wrong?
My environment setup:
Mac OSX 10.14
Visual Studio for Mac COMMUNITY 7.7.4(build 1)
Target framework: .NET 4.7.1
Thank you so much for any help!
Try change to 64 bit.
This may not correct answer to you. But give a try.
I dont have mac environment. But I tried woth .net core and TensorflowSharp and it works fine.
Same time I tried with .net framework and I also got dll not found issue and BadImageFormatException.
https://github.com/migueldeicaza/TensorFlowSharp/issues/103
https://github.com/migueldeicaza/TensorFlowSharp/issues/103

Application crashes on debugging a web project with exit code -2147023895 (0x800703e9) in Visual Studio 2017

I am trying to debug a web api project on a newly setup laptop with Visual studio 2017 professional edition.
It uses Target framework of .NET Framework 4.6.1.
The web application (not visual studio) crashes few seconds after starting with this in the output window.
The program '[4868] iisexpress.exe' has exited with code -2147023895 (0x800703e9).
And for every crash, I see this message in Event Viewer
The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
(devenv.exe, PID 24968, Thread 1) IdleProcessorManager.DoWork - Job threw:
Invalid URI: The format of the URI could not be determined. at
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at Microsoft.VisualStudio.TestTools.TestCaseManagement.SolutionIntegrationManager.IsRunConfig(String filename)
at Microsoft.VisualStudio.TestTools.TestCaseManagement.SolutionIntegrationManager.d__351.MoveNext()
at Microsoft.VisualStudio.TestTools.TestCaseManagement.IdleProcessorManager.DoWork()
The message resource is present but the message was not found in the message table
I already tried deleting .vs folder, restarting pc, uninstall/install vs, uninstall/install .net framework amongst other things.
Can someone help me fix this, unable to get to the 'real' reason for these failures.
Things to note -
1. The project works fine on other machines.
2. I can create a new project using project template and run/debug application successfully.
EDIT : On more investigation I find that the web application breaks (without any error other than the exit code) and exits.
public virtual DataSet Execute(SqlCommand sqlCommand, SqlConnection sqlConnection)
{
if (sqlCommand == null || sqlConnection == null)
{
return null;
}
var ds = new DataSet();
if (sqlConnection.State != ConnectionState.Open)
{
sqlConnection.Open();
}
using (var adp = new SqlDataAdapter(sqlCommand))
{
adp.Fill(ds); <---- BREAKS here!
return ds;
}
}
On another machine where its working, it works perfectly fine. And the SP returns around 390K records. Possible stackoverflow exception?
Please check the Framework versions that are installed to your new laptop.
I suspect that the minor versions don't match wiht your new laptop.
You can check which versions are installed to your machine via the link:
https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed
Edit:
1- Install the version from :
https://www.microsoft.com/en-us/download/details.aspx?id=49981
2- Or I recommend you to upgrade your Project's framework to .NET Framework 4.7.2

How to deploy a .net dll, which invokes UWP OCR API in it?

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
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

Error MCG0004:InternalAssert Assert Failed when building UWP app in release mode

I have an UWP app written in C# which builds (VS 14.0.25425.01 Update 3 on Windows 10.0.14393, target version of the project is build 14393) and runs in Debug mode, but fails to build in Release mode with the following error:
Microsoft.NetNative.targets(640,5): error : MCG0004:InternalAssert Assert Failed: field not found during [UNKNOWN]
There are no further details, except for two warnings before, which I am not sure whether they are related to the problem:
Resources.System.Linq.Expressions.rd.xml(35): warning : ILTransform : warning ILT0027: Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found.
Resources.System.Linq.Expressions.rd.xml(91): warning : ILTransform : warning ILT0027: Method 'ParameterIsAssignable' within 'System.Linq.Expressions.Expression' could not be found.
Any suggestions what the issue could be related to?
This error will occur if you're using the Beta package for .NET UWP tools with VS 2015. The Beta package is only supported on 2017 as there are changes to how deployment/debugging work that we rely on. You should be able to avoid the issue by downgrading from "Microsoft.NETCore.UniversalWindowsPlatform": "5.3.0-beta2" to "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2"
edit: 5.3.0 has been published and works with VS2017 RC3+. More information here: https://blogs.msdn.microsoft.com/dotnet/2017/01/30/announcing-net-core-net-native-and-nuget-updates-in-vs-2017-rc/
Disclaimer: I work on the .NET Native compiler+runtime team.

Categories

Resources