Critical Internal Error when adding a block written in C#
Hello,
In my project I have several FB's written in C#, so far they are working fine, but today I added a new one and got the Critical Internal Error below:
Error | E1001: [optiPoint]OptipointLearningModule.compareMCV.compareMCVMainMethod() IL_00DC : critical internal error | |
Error | CILC0001 | Error during generating native code. |
My code compiles with no errors on Visual Studio, what does that error mean?
Thanks
Comments
Hello,
first of all a short explenation about compiling in Visual Studio and in the PLCnext Engineer.
Visual Studio compiles your C# code to CIL code (Common Intermediate Language). This is what Visual Studio does with any .NET programming language. This CIL code is normaly run by a Just-In-Time compiler(JIT) as part of a Common Language Runtime (CLR). This is responsible to execute and manage .NET programs regardless of the .NET language its coming from. Our Visual Studio Addin just provides a profile to restrict the use of available C# namespaces/methods, to a set interpret able by our compiler. The CIL code/intermediate language is then converted into the machine code, in a typical .NET environment by the Just-In-Time (JIT) compiler. This machine code is specific to the computer environment that the JIT compiler runs on. In the case of PLCnext Technology we have the eCLR CIL compiler. Different to a JIT compiler, the eCLR CIL compiler is an ahead-of-time compiler and already compiles the intermediate (CIL) code on your host machine for the target set in the PLCnext Engineer.
Now to your issue, it looks like the eCLR CIL compiler integrated in the PLCnext Engineer is not able to compile your newly added FB. It could be a small issue due to an unsupported pattern you used. Can you provide me the C# code of your new function block? In case you can't publish it here, shall I contact you via Mail for exchange the information?
~ Marcel
Thanks Marcel,
I would prefer not to post my code, but here is my email: asanchez@armstrongfluidtechnology.com
Please send me your contact so I can share the code. In the mean time I will trim down my code to see if I figure out what is causing the error.
Regards,
Alex
Hi Marcel,
After some trial and error we deduced that a C# DateTime data type cannot be used as an argument in a method that is used in the PLC code.
The data that was in Type DateTime was replaced with Int and the PLC accepted it.
Thanks,
Alex
Hi Alex,
The valid data types that can be used in C# FBs are listed in the Readme.txt file that is included in every C# project, and in this table in the Info Center:
https://www.plcnext.help/te/Programming/Csharp/Csharp_Supported_data_types.htm
In addition, there are examples showing how to pass Date and Time variables to C# FBs, here:
https://github.com/PLCnext/CSharpExamples/blob/master/PLCnext_CSharpExamples/09_DateTime/DateTime.md
You can see that you are able to use the "DataType" attribute modifier to force the user to pass a variable of the correct IEC datatype, e.g. "LDATE_AND_TIME".
~ Martin.