Search code examples
reporting-servicesaxaptadynamics-ax-2012dynamics-ax-2012-r3

System.Byte[] gives unexpected value


I have a strange issue in one of the production servers. We have an architecture in which we have integrated AX using web services with a .NET app. We use System.IO objects to convert a pdf report into bytes and send this info through web services to the app. The method we use worked fine until recently when we started seeing strange results. The byte array returned on the production environment was different from rest of the environments. The code base obviously is the same on all environments. The byte array had a large number, something like 47000 and rest of the environments give approx 3000. This causes issues with generating a report in app.

Just to add to above, the report in question is an AX SSRS report of an item and its barcode. The report prints fine in AX client. But to pass it to web services the report is converted into bytes and sent to the app that then converts it back into an image and displays on the UI. Because of the difference in bytes returned on production, the image thats printed has the item number but not the barcode. Instead of barcode, shows a blank white space. I have checked that the barcode fonts are installed on the SSRS server and if i print the report directly in AX, it prints fine. I know the architecture could have been simpler but thats what i have at the moment and need to make it work. Any help will be appreciated. Thanks.

static System.Byte[] test()
{
    str _filePath = "C:\\Users\\Harry\\Desktop\\ABC.PDF";

    System.Byte[]           pdfBuffer;
    System.IO.FileInfo      fileInfo;
    System.IO.FileStream    fs;
    int                     size;
    Set                     permissionSet = new Set(Types::Class);

    permissionSet.add(new FileIOPermission(_filePath,'r'));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

    CodeAccessPermission::assertMultiple(permissionSet);

    //Load the file
    fileInfo = new System.IO.FileInfo(_filePath);
    //Initiallize the byte array by setting the length of the file
    size = int642int(fileInfo.get_Length());
    pdfBuffer = new System.Byte[size]();
    // Stream the file
    fs = new System.IO.FileStream(fileInfo.get_FullName(), System.IO.FileMode::Open, System.IO.FileAccess::Read);
    fs.Read(pdfBuffer, 0, pdfBuffer.get_Length());
    fs.Close();
    fs.Dispose();

    //Revert the access
    CodeAccessPermission::revertAssert();

    return pdfBuffer;    
}

Solution

  • Solution was to install the barcode fonts on the reporting server AND restart the server. We had delayed restarting the server. To find the font you need, generate the ssrs report in AX client and export it to pdf. From the Adobe reader you can check the properties of the report and see the barcode required on the fonts tab. Thats your font.