web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

System.Byte[] gives unexpected value

(0) ShareShare
ReportReport
Posted on by

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;    
}


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Are you saying that you get different bate array for the identical file on different systems? If you just assume that the same file is passed to this logic, please test this assumption. Different bytes means different data, therefore more likely explanation is that the files are different (one has 3000 bytes and the other 47000).

  • Community Member Profile Picture
    on at

    Hi Martin

    The issue is resolved. When i try to export the report as pdf the barcode is left out because the font is not installed on the SSRS server. We had installed the font on SSRS server very early but DID NOT restart the server as its a production server. This was a problem. We restarted the server and it worked. And its the same file that shows different no of bytes. Thanks a lot for your response.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You see that the files weren't the same - one contained the barcode and the other didn't (if I understand your description correctly). Different size of files obviously means different number of bytes.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans