C# DateTime Cannot be Used as a Method Argument

Stumbled on this odd behavior and eventually figured it out, no thanks to an extremely opaque error message: Error E1001: [optiPoint]OptipointLearningModule.compareMCV.compareMCVMainMethod() IL_00DC : critical internal error Error CILC0001 Error during generating native code.

After a bit of trial and error it became clear that you can’t use a C# DateTime type as an argument in a method for the PLC.
Further complicating the search was the fact that the code compiles fine if the method with the DateTime argument is not used by some other method.

I checked the “Known Issues and Constraints” section in the eCLR 3.2 Programming Reference but found nothing on this. Might be worth adding?

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.