Page 1 of 1

.Net KM_Controller.Compile() error

Posted: Fri Nov 16, 2018 7:22 pm
by akorchak
I'm trying to compile c code file using .Net KM_Controller.Compile() method. I'm getting the following error:

Code: Select all

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.String..ctor(SByte* value)
   at System.StubHelpers.CSTRMarshaler.ConvertToManaged(IntPtr cstr)
   at KMotion_dotNet.KM_Controller.KM_dotnet_Interop_Compile(IntPtr handle, Int32 boardtype, Int32 threadID, String name, String& outfile, String& error, Int32 _ErrorLength)
The issue doesn't seem to be caused by a particular .c file (tried few of them - same result). The same files are being compiled/executed from KMotionCNC without any issues.

Tried with KMotion versions 4.3.3 and 4.3.4 - same result.

Would appreciate any help. Thanks.

Re: .Net KM_Controller.Compile() error

Posted: Fri Nov 16, 2018 7:37 pm
by TomKerekes
Hi akorchak,

Did you allocate memory for the return strings?

Can we see your code?

Re: .Net KM_Controller.Compile() error

Posted: Fri Nov 16, 2018 10:02 pm
by akorchak
Hi TomKerekes,

Thanks for the response.

No, I did not explicitly allocate memory for the return string (should I?). Here is my code (used "PC VCS Examples\KMotion_dotNet Console" as a template):

Code: Select all

_Controller = new KMotion_dotNet.KM_Controller();
string thefile = @"C:\KMotion434\C Programs\ToolChange.c";
String result = _Controller.Compile(4, thefile);

Re: .Net KM_Controller.Compile() error

Posted: Sat Nov 17, 2018 2:08 am
by TomKerekes
Hi akorchak,

Oops you are correct. That routine is rarely used and has several bugs. This will be fixed in the next release.

In the meantime please use CompileAndLoadCoff() instead:

String result = _Controller.CompileAndLoadCoff(4, thefile, false);