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
Related
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
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 have the following function that I am attempting to use to determine the length of an MP3 file:
public static string GetMP3DurationBackup(string Filename)
{
string Duration = null;
WMPLib.WindowsMediaPlayer w = new WMPLib.WindowsMediaPlayer();
WMPLib.IWMPMedia m = w.newMedia(Filename);
if (m != null)
{
Duration = m.durationString;
}
w.close();
return Duration;
}
I have run into an issue where I get the following error:
Retrieving the COM class factory for component with CLSID
{6BF52A52-394A-11D3-B153-00C04F79FAA6} failed due to the following
error: 80040154..
when I call the above function from my web application (call below):
string test = MediaUtil.GetMP3DurationBackup(#"C:\Temp\Audio\bad.mp3");
But when I call it from a console application test harness I created (exact same call as above) it works fine. I have set the project that contains the function to target x86 in the Build properties, but that did not fix the issue.
Does anyone know why this would happen? Suggestions on where to start to debug this?
UPDATED FOR BOUNTY:
Ok, I've tried a number of things but I am still getting this error. Among other things I have tried the steps below which I felt were the most promising, but no dice:
Went into my registry and confirmed that the value at:
HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{6BF52A52-394A-11d3-B153-00C04F79FAA6}\InprocServer32
is refering to C:\WINDOWS\SysWOW64\wmp.dll
Opened command prompt,
navigated to C:\WINDOWS\SysWow64, ran: regsvr32.exe wmp.dll
I have created a console app test harness and I am able to reproduce the error if I run the test project in x64. If I switch it to x86 it works fine.
Does anyone have any idea of why the above would not resolve the issue? Suggestions on where to look next?
You say it doesn't work in x64, but you try to register the 32-bit version of wmp.dll (C:\Windows\SysWow64 contains 32-bit assemblies).
Try to register the x64 version of wmp.dll, which is located in C:\Windows\System32 on a 64-bit platform.
If you don't have this file then there probably is no 64bit Windows Media Player available for your platform. But there is a workaround:
Create a 32-bit console application that takes the mp3 filename as command line argument and outputs the duration to stdout using Console.WriteLine, then in the webapp, you call the console application and capture the output like in this example on MSDN
Give this lib a whirl. Its fast and has no special requirements for software to be installed on the machine.
http://naudio.codeplex.com/
I've run across an issue when debugging applications on VS 2010.
This is a simple command-line app:
namespace HttpTest
{
class Program
{
public void testHTTP ()
{
Console.WriteLine("Creating HTTP request. Press a key to proceed.");
Console.ReadKey();
var request = (HttpWebRequest)HttpWebRequest.Create("http://stackoverflow.com");
Console.WriteLine("Getting response...");
var response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Done");
Console.ReadKey();
}
static void Main(string[] args)
{
Program app = new Program();
app.testHTTP();
}
}
}
If I launch/debug it from Visual Studio 2010, I get a ConfigurationErrorsException when creating the HttpWebRequest:
Error creating the Web Proxy specified in the 'system.net/defaultProxy' configuration section.
This is quite suprising, as my app.config has no entry in system.net/defaultProxy (and neither does my devenv.exe.config).
By trying different settings, I found out that the error only happens if I set the target framework to 4.0 and the target platform to x86 and try to debug within VS
If I build it and run it from the command line (regardless of build settings), I have no issues.
If I set the target Framework to 3.5, the error disappears and the app debugs normally.
If I set the platform target to 'x64' or 'Any CPU', the app debugs normally.
If I build on 4.0/x86, run from command line, attach the debugger while waiting for the first key press, then proceed, I get the error mentioned above.
I have disabled the firewall on my machine
Running VS as administrator makes no difference to the test.
If I try this on a different machine, same hardware specs and OS, belonging to a colleague, I can debug it within VS2010.
It obviously has something to do with the settings on my machine. However, I have been unable to isolate what the conditions are.
Other users suggested moving the application to the C: drive. I don't think this applies to my case, as I can run int successfully from the D: drive. Issue happens only when debugging within VS.