Showing posts with label Compile. Show all posts
Showing posts with label Compile. Show all posts

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.

Monday, 9 February 2015

Phantom objects in USR layer after compile using AXBuild

Recently we performed a cleanup of USR layer and moved the objects (created wrongly in that layer) to CUS layer or removed them if they were not required as we are supposed to have nothing in USR layer. We then removed the USR model using AXUtil. This went well until we noticed that there are some objects in USR layer. These included some classes and forms. Recompiling was bringing these objects back even if we remove these.

Examining these objects, we found that none of these have any difference from the layer below. These phantom objects were created while the application was compiled using AXBuild. A client compile was not creating these phantom objects.

So we contacted MS and were advised to apply KB 3015739 which is a binary hotfix. This however did not fix our issue. One of my colleague later discovered that if we pass an additional un-documented parameter /layer=cus to AXBuild, these phantom objects are not created.

Not sure if this parameter was present before or it was introduced due to the KB that we applied but it fixed out issue.

We are on AX2012 R2 with CU7.

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