Monday, 2 March 2015

.NET Cast Type Name not found error

Last week I was trying to fix a bug in custom code where we import the POs. The bug was in the following method.
protected AnyType getData(int _position, Container _data = currentData)
{
    str data = conpeek(_data, _position);
    data = strRem(data,'"');
    
    if( _position == str2int(#13)
     || _position == str2int(#14))
    {
        data = this.formatDate(data);
    }

    return data;
}
The fix for the bug was to check for another position #07 and convert the data to date format. So I changed the code to following
protected AnyType getData(int _position, Container _data = currentData)
{
    str data = conpeek(_data, _position);
    data = strRem(data,'"');
    
    if( _position == str2int(#13)
     || _position == str2int(#14)
     || _position == str2int(#07))
    {
        data = this.formatDate(data);
    }

    return data;
}
Note the position of #07 in the if statement. The compile was fine however when I generated IL it gave the following error. Incremental or full IL, both produced the same error.
CIL generation: Error: .NET Cast Type Name not found. Type System.String found on the stack. This code in Class/Table: POImportService, Method: getData may not work in CIL run time.
I moved the position of #07 as shown below and the error disappeared.
protected AnyType getData(int _position, Container _data = currentData)
{
    str data = conpeek(_data, _position);
    data = strRem(data,'"');
    
    if( _position == str2int(#07)
     || _position == str2int(#13)
     || _position == str2int(#14))
    {
        data = this.formatDate(data);
    }

    return data;
}
Not sure why IL does not like the #07 line to be the last one.

This posting is provided "AS IS" with no warranties. Use code at your own risk.