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
Related
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.
I'm trying to get pythonnet to work in my .Net Core app running on Linux.
I've made a reference to Python.Runtime.dll (which I got from nuget) in my .Net Core project.
My code is:
using System;
using Python.Runtime;
namespace pythonnet_w
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Start");
using (**Py.GIL()**) {
// blabla
}
Console.WriteLine("End");
}
}
}
I get this runtime error:
Unhandled Exception: System.MissingMethodException: Method not found: 'System.Reflection.Emit.AssemblyBuilder
System.AppDomain.DefineDynamicAssembly(System.Reflection.AssemblyName, System.Reflection.Emit.AssemblyBuilderAccess)'.
at Python.Runtime.CodeGenerator..ctor()
at Python.Runtime.DelegateManager..ctor()
at Python.Runtime.PythonEngine.Initialize(IEnumerable`1 args, Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize(Boolean setSysArgv)
at Python.Runtime.PythonEngine.Initialize()
at Python.Runtime.Py.GIL()
at pythonnet_w.Program.Main(String[] args) in D:\Development\~.Net libraries (3.part)\phytonnet\.Net Core test (phytonnet)\c#\pythonnet_test\Program.cs:line 10
/usr/sbin/pythonnet_w: line 5: 19487 Aborted dotnet "/usr/share/pythonnet_wit/pythonnet_w.dll"
Tried to find a solution in these threads but without any luck:
How do I run a py file in C#?
Call Python from .NET
UPDATE:
I tried to open \pythonnet-master\src\runtime**Python.Runtime.csproj** in Visual Studio to see if I can compile it to .Net or .Core, but I can only compile to .Net framework.
I found this article "How to port from .net framework to .net standard"
Is that what I have to do?
I finally had success by using a self-compiled Python.Runtime.dll as of version 2.4.0. There are two options to create a working DLL:
Remove the other target framework net461 from the respective project file (leaving only netstandard2.0).
Run dotnet build using the appropriate options
For option 2, the following works(in Windows, Mac and Linux):
Clone the pythonnet repo (https://github.com/pythonnet/pythonnet)
In the pythonnet folder, cd src\runtime
Run dotnet build -c ReleaseWinPY3 -f netstandard2.0 Python.Runtime.15.csproj in Windows(in Mac/Linux, replace ReleaseWinPY3 with ReleaseMonoPY3 because the former use python37 and the later use python3.7)
Set DYLD_LIBRARY_PATH in Mac or LD_LIBRARY_PATH in linux(Windows skip):
export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.7/lib
Use the built DLL bin\netstandard2.0\Python.Runtime.dll as DLL reference in your Visual Studio .NET Core project (mine targets netcoreapp2.2, netcoreapp3.1 is also tested ok), e.g. in conjunction with the following code,
using System;
using Python.Runtime;
namespace Python_CSharp
{
class Program
{
static void Main(string[] args)
{
using (Py.GIL())
{
dynamic os = Py.Import("os");
dynamic dir = os.listdir();
Console.WriteLine(dir);
foreach (var d in dir)
{
Console.WriteLine(d);
}
}
}
}
}
You can host the IronPython interpreter right in your .NET application. For example, using NuGet, you can download the right package and then embed the script execution (actually the IronPython engine) right into your application.
Ref:
https://medium.com/better-programming/running-python-script-from-c-and-working-with-the-results-843e68d230e5
Just installed MonoDevelop and I tried to compile a simple "Hello World".
Code I used:
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
The error that I get is :
EmptyCSharpFile.csproj(1,1): Error: Unknown MSBuild failure. Please try building the project again (EmptyCSharpFile)
My system info:
Ubuntu 16.04 LTS , updated
The MonoDevelop and mono are freshly installed.
Mono JIT compiler version 5.0.1.1
MonoDevelop Version 5.10
I can use mcs and run it but can't use monodevelop to run it.
I did read these similar topics but no response yet:
MonoDevelop Failure "Unknown MSBuild Failure" on Linux ;
C# compile Unknown MSBuild error MonoDevelop Linux ; https://askubuntu.com/questions/73630/could-not-obtain-c-compiler-error-when-using-monodevelop
I too had the same problem when I first installed it , I assume you went straight to file -> new-> file-> general -> emptyc# file.
Instead of that, go to file->new-> solution from there choose Console C# project or simply press ctrl + shift + N choose next ,and give project name, by default the new project has a simple hello world program run it, this time it will work.(it worked for me)
I just installed MonoDevelop on my Ubuntu machine, and attemtepted to run a hello world, just to test it out:
using System;
public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}
...but when building it gives an "Unknown MSBuild failure" error
I have tested Mono before using MonoDevelop and verified that it works.
This is most likely due to an error or errors during compilation, which oddly enough, MonoDevelop is not telling you.
Assuming you have mono itself installed, open a terminal and compile from there(source):
mcs HelloWorld.cs
I have had similar issue with a project that used to work - it seems error is in the package NUnit, however I have not yet found a solution for it - have a look at your packages, perhaps you find your issue there
Hopefully someone has a little time to explain how to use V8.Net with Mono.
I'm trying to use V8.Net with mono 3.10 on my ubuntu machine. So far I did the following:
create an example project with the content on codeplex
using System;
using V8.Net;
namespace testv8
{
class MainClass
{
public static void Main (string[] args)
{
var v8Engine = new V8Engine();
Handle result = v8Engine.Execute("/* Some JavaScript Code Here*/","My V8.NET Console");
Console.WriteLine(result.AsString); // (or "(string)result")
Console.WriteLine("Press any key to continue ...");
Console.ReadKey();
Console.WriteLine ("Hello World!");
}
}
}
add V8.Net.dll and V8.NetSharedTypes to the references
I copied the content of the folder /Release/NET 4.0/x64 to /bin/Debug/x64 of my build directory
When I try to run the example, I get the following error: A system.DllNotFoundException was thrown.
I changed the Build type from Debug to ( Debug | Any cpu ). If I understood correct the library should now choose the correct dll.
6 When I rerun the program in this mode.
The program stops at:
Loaded assembly: /Build/v8dotnet/testv8/testv8/bin/test/x64/V8.Net.Proxy.Interface.x64.dll [External]
The call stack shows:
V8.Net.V8NetProxy.CreatehandleProxyTest().
Hopefully you can give me some input to get it running.
Short note: there is some progress on making V8.Net available with Mono for different platforms (Win, Linux, and Mac).
More info is available on the following sites:
Mono Github Branch
V8.Net Mono Issues
Update: Mono is no longer supported. .Net Standard is now supported instead, which is cross-platform also.
NuGet: https://www.nuget.org/packages/V8.Net/
CodePlex is now closed down. The new source is here: https://github.com/rjamesnw/v8dotnet