3
$\begingroup$

I can successfully load and run methods of a static class I have written in c# using:

Needs["`NETLink"];
ReinstallNET[
 "MonoPath" -> 
  "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono",\
 "Force32Bit" -> True];
LoadNETAssembly["/path/to/library.dll"];
LoadNETType["Namespace.StaticClassName"];
NameSpace`StaticClassName`Method[Arguments];

However if my library (library.dll) uses any packages from nuget then I get the following error on the last line (in this example I am trying to use Newtonsoft.Json package - but I have tried others with the same result):

"A .NET exception occurred: \!\(\"System.IO.FileNotFoundException: \
Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, \
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its \
dependencies.\\\\nFile name: 'Newtonsoft.Json, Version=12.0.0.0, \
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'\\\\n  at (wrapper \
managed-to-native) \
System.Reflection.MonoMethod.InternalInvoke(System.Reflection.\
MonoMethod,object,object[],System.Exception&)\\\\n  at \
System.Reflection.MonoMethod.Invoke (System.Object obj, \
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder \
binder, System.Object[] parameters, System.Globalization.CultureInfo \
culture) [0x0003b] in <98fac219bd4e453693d76fda7bd96ab0>:0 \"\)."

The library compiles fine and I can use the library functions from other C# code without any issues. What am I doing wrong? I am on OSX if that is relevant.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.