Strange CLR Interop issue

Hello,

I am receiving the runtime error, “Wrong arguments types in variable assignment”, when using the following code:

private str getFileDateTimeString()

{

System.DateTime dateTime = fileDateTime;

System.String outputFormat;

InteropPermission perm;

;

perm = new InteropPermission(InteropKind::ClrInterop); //<< Where error occurs

if (perm == null)

{

throw error(“CLR Interop error. You do not have sufficient permissions.”);

}

perm.assert();

outputFormat = CLRInterop::getObjectForAnyType(“YYYYMMDDHHMMSS”);

return dateTime.ToString(outputFormat);

}

Any thoughts on why and how I can get this code to run correctly?

Thank you!

Ok, so I rewrote this code to make it simpler and now it looks like this:

private str getFileDateTimeString()

{

System.DateTime dt = DateTimeUtil::utcNow();

str s = dt.ToString(‘yyyyMMddHHmmss’);

;

return s;

}

The code above produces the same error! :frowning:

However, as a job it works:

static void dotNetTestDateFormat(Args _args)

{

System.DateTime dt = DateTimeUtil::utcNow();

str s = dt.ToString(‘yyyyMMddHHmmss’);

;

info(strfmt("%1", s));

}

Any thoughts?

Well, this finally worked. Notice that I needed to make it static and assert the permissions:

public static str getFileDateTimeString(UTCDateTime _fileDateTime)

{

InteropPermission permission;

System.DateTime dt;

str sDate;

;

permission = new InteropPermission(InteropKind::ClrInterop);

permission.assert();

dt = Global::utcDateTime2SystemDateTime(_fileDateTime);

sDate = dt.ToString(‘yyyyMMddHHmmss’);

return sDate;

}