I'm trying to call Prolog script file from C# program using SWI Prolog. I downloaded the code package from github (using this link). But, when I'm trying to run the HelloWorldDemo program the following error occurs:
System.IO.FileNotFoundException: 'The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
on Line 105 on the following code:
private static void LoadUnmanagedLibrary(string fileName)
{
if (_hLibrary == null)
{
_hLibrary = NativeMethods.LoadDll(fileName);
if (_hLibrary.IsInvalid)
{
int hr = Marshal.GetHRForLastWin32Error();
Marshal.ThrowExceptionForHR(hr); //here the error occurs
}
}
}
I tried many solutions on the Internet, for example, provide the swi path on setenviromentvariable but the error still same.
Here is the code of HelloWorldDemo.cs:
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SWI_HOME_DIR", #"C:\Program Files\swipl\"); // I also used C:\Program Files\swipl\bin and didn't help too
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("assert(father(martin, inka))");
PlQuery.PlCall("assert(father(uwe, gloria))");
PlQuery.PlCall("assert(father(uwe, melanie))");
PlQuery.PlCall("assert(father(uwe, ayala))");
using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["L"].ToString());
Console.WriteLine("all children from uwe:");
q.Variables["P"].Unify("uwe");
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["C"].ToString());
}
PlEngine.PlCleanup();
Console.WriteLine("finshed!");
}
}
So, how can I fix this issue?
Note: I'm using Win10 x64, visual studio 2017 community.
Related
I am following a tutorial, in one step it opens "VS2012 arm cross tools command prompt" and executes
xsd file.xsd /classes
I can't find "VS2012 arm cross tools command prompt" on my computer (my guess it's because I'm using VS2019) so I open the "Developer command prompt for VS 2019" instead, but when I run the command, I get an error:
"xsd" is not recognized as an internal or external command, program or executable batch file
Can someone tell me how I can create a class from an xsd file in VS 2019? Thank you for your time.
Once you have installed the Windows SDK. The following could be of help to you...it is .NET Core. Browse to the xsd.exe and add a reference to it in VS 2019.
class Program
{
static void Main(string[] args)
{
var rgs = new string[]
{
#"PathToYourDLL\My.dll",
"/type:ClassNameToGen"
};
AppDomain.CurrentDomain.FirstChanceException += (s, e) =>
{
string error = e.Exception.ToString();
var typeLoadException = e.Exception as ReflectionTypeLoadException;
if (typeLoadException != null)
{
foreach (var exception in typeLoadException.LoaderExceptions)
{
error += Environment.NewLine + Environment.NewLine + exception.ToString();
}
}
Console.WriteLine(error);
};
XsdTool.Xsd.Main(rgs);
Console.ReadLine();
}
}
I am using Visual Studio 2019 on Windows 10 with Google Speech API for a .NET Console project using C# with the following code:
class Program
{
static async System.Threading.Tasks.Task<object> AsyncRecognizeGcsAsync()
{
var URI = "https://speech.googleapis.com/v1/speech:recognize?key=...";
var speech = SpeechClient.Create();
var longOperation = speech.LongRunningRecognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
SampleRateHertz = 44100,
AudioChannelCount = 2,
LanguageCode = "en",
}, RecognitionAudio.FromStorageUri(URI));
longOperation = longOperation.PollUntilCompleted();
var response = longOperation.Result;
Console.WriteLine("response.Results.Count = " + response.Results.Count);
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine($"Transcript: { alternative.Transcript}");
}
}
return 0;
}
static void Main(string[] args)
{
Console.WriteLine("Start!");
AsyncRecognizeGcsAsync();
}
}
This is what I get in the Output Window:
Exception thrown: 'Grpc.Core.RpcException' in System.Private.CoreLib.dll
The program '[22028] dotnet.exe' has exited with code 0 (0x0).
This is what I get in the Command Line Console:
Start!
**********
C:\Program Files\dotnet\dotnet.exe (process 25260) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
How do I find out what the RpcException is? How do I go about fixing this?
I tried this answer on stackoverflow, but it didn't solve the problem.
I have problem with connecting Prolog to C#.
Visual Studio gives this following error :
"An unhandled exception of type 'System.IO.FileNotFoundException'
occurred in SwiPlCs.dll"
and I really don't know how to handle this.
I think it came from the path I gave in the code :
using System;
using SbsSW.SwiPlCs;
namespace ptest
{
class Program
{
static void Main(string[] args)
{
//Environment.SetEnvironmentVariable(#"C:\Program Files\swipl", #"C:\Program Files\swipl\boot64.prc"); // or boot64.prc
var curPath = Environment.GetEnvironmentVariable("C:\\Program Files\\swipl\\bin");
Environment.SetEnvironmentVariable(#"C:\Program Files\swipl\bin", #"C:\Program Files\swipl\boot;C:\Program Files\swipl;" + curPath);
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("assert(father(martin, inka))");
PlQuery.PlCall("assert(father(uwe, gloria))");
PlQuery.PlCall("assert(father(uwe, melanie))");
PlQuery.PlCall("assert(father(uwe, ayala))");
using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["L"].ToString());
Console.WriteLine("all children from uwe:");
q.Variables["P"].Unify("uwe");
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["C"].ToString());
}
PlEngine.PlCleanup();
Console.WriteLine("finshed!");
}
}
}
}
Please Help me. Thank you very much.
I think its a problem with latest versions of SWI_Prolog. Try installing older version of SWI-Prolog 6.6.1 for Microsoft Windows (32 bit) in C:/Program Files (x86) and use SwiPlCs_1.1.60301.0.zip. Add reference to SwiPlCs.dll in Visual Studio. It will work IA :)
In my ASP.Net mvc 5 application I use MWArray.dll and a matlab function that I generated .dll via Matlab's Library Compiler.
Everything works fine on localhost, but on VDS I rented there is a problem
The exception throwed with the message of "The type initializer for 'MathWorks.MATLAB.NET.Arrays.MWNumericArray' threw an exception."
Inner exception is
"The type initializer for 'MathWorks.MATLAB.NET.Utility.MWMCR' threw an exception."
One more Inner Exception is
"Unable to load DLL 'mclmcrrt9_0_1.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
And after I change the dll's with native versions, I get
"Unable to load DLL 'mclmcrrt9_0_1.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"
Error.
here is the controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using average; //dll that generated via Matlab Compiler SDK
namespace EleDeneme.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
Random rnd = new Random();
string[] foo;
string result = string.Empty;
try
{
using (MWNumericArray matrix1 = new MWNumericArray(new double[20]))
{
for (int i = 1; i <= 20; i++)
{
if (i % 3 == 0)
{
matrix1[1, i] = rnd.Next(100);
continue;
}
matrix1[1, i] = rnd.Next(10);
}
using (average.DenemeClass deneme = new DenemeClass())
{
using (MWArray res = deneme.average(matrix1))
{
//for (int i = 0; i < res.NumberOfElements; i++)
//{
var asdf = res.ToArray();
foo = asdf.OfType<object>().Select(o => o.ToString()).ToArray();
foreach (var item in foo)
{
result += item + " ";
}
Response.Write(result);
//}
}
}
}
}
catch (Exception ex)
{
result = ex.Message;
Response.Write(result);
}
return View();
}
}
}
the average.dll is a matlab functions compiled version for .net . Also here is the MATLAB code,
function y = average(x)
if ~isvector(x)
error('Input must be a vector')
end
y = sum(x)/length(x);
end
before all your answers, I have installed Matlab Compiler Runtime that compatiable with Matlab R2016a to the VDS's C:\Program Files\MATLAB...
I changed IIS applicationpool and my aplications configurations as
IIS 32bit disabled
but still I got the exception same as the exception first time I published to the server.
LocalHost, working Fine (19.9 is my matlab functions output)
I need to get the names from the smartcard on my computer from inside a service.
I have this program to write the names of all smartcards to a file.
using System;
using System.Threading.Tasks;
using Windows.Devices.Enumeration;
using Windows.Devices.SmartCards;
namespace DeviceEnumerationConsoleTest
{
class Program
{
static void Main(string[] args)
{
EnumerateDevices().Wait();
}
static async Task EnumerateDevices()
{
try
{
string selector = SmartCardReader.GetDeviceSelector();
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
string ret = "start1 ";
foreach (DeviceInformation device in devices)
{
ret = ret + device.Name + " _ ";
}
System.IO.File.WriteAllText(#"C:\ProgramData\IDNORTH\cards.txt", ret);
}catch(Exception e)
{
System.IO.File.WriteAllText(#"C:\ProgramData\IDNORTH\error.txt", e.Message);
}
}
}
}
This work great when I run it on it's own.
However when I run it from outside it sometimes work and sometimes returns
Method not found: Void System.Threading.Tasks.Task.AddToActiveTasks(System.Threading.Tasks.Task).
from line:
DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector);
I believe from the error there is some problem with the dlls.
In project I have added the references.
C:\Program Files (x86)\Windows Kits\8.1\References\CommonConfiguration\Neutral\Windows.winmd
and
C:\Program Files (x86)\Microsoft SDKs\WindowsPhoneApp\v8.1\Tools\MDILXAPCompile\Framework\System.Runtime.WindowsRuntime.dll
I call the exe from a service and have not added or changed any references in that. It has the same windows reference as the one added to Project1.
Not sure if this is the procedure but thought I should mark this as answered since it works now.
Changed the reference to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
Thanks to Default!