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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Error while getting docuref attachment stream

(0) ShareShare
ReportReport
Posted on by 172

Hi,

I got a problem adding a attachmentstram from docu ref on specific customers only on sales invoices.

So.. this problem occours only on some customers and only on sales invoices. The same customers on projinvoices have no problem.

It finds the docuref but the moment it try to addAttachment it exits the method and in output I have only this error.

Exception thrown: 'System.NullReferenceException' in Microsoft.Dynamics.AX.Framework.FileManagement.dll

I had a similar problem with the same customer group but with creating invoices. That time salesinvoiceheadertmp table didn't cleared data and blocked output on invoices lines.

Could be there a similar problem with a tmp table? Where could I look after?

if (docuRef)
                {
                    System.IO.Stream stream = DocumentManagement::getAttachmentStream(docuRef);  // <---
                    cmrFile = filePath   docuRef.originalFileName();
                    System.IO.FileStream fileStream = new System.IO.FileStream(cmrFile, System.IO.FileMode::Create, System.IO.FileAccess::ReadWrite);
                    stream.CopyTo(fileStream);
                    fileStream.Close();
                }

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RadekM,

    Is it PROD or sandbox or dev environment?

    Can you check if the file is really attached and you can download it manually?

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

    What's the value of cmrFile variable? Maybe it's not a valid path.

  • RadekM Profile Picture
    172 on at

    The same problem is across all platforms.

    On my dev im working on a old database. This files are already marked as send on  PROD but i can't make this happen on dev. THe same error is on prod on new crm's and on my dev with old crm that did worked before on prod.

    I don't reach the cmrFile variable. It stops right on getattachment, that is the last breakpoint it touch. This variable is used just after its value is declared there.

    Filename cmrFile;

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RadekM,

    Have you checked if the file is attached physically and you can download it manually from UI?

  • RadekM Profile Picture
    172 on at

    Yes, I can open it and download it.

  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi RadekM,

    Does the issue constantly reproducible on the same file?

  • RadekM Profile Picture
    172 on at

    Yes. This problem occourd always on some customers. I have different invoices with different CMR on one customer and they all fail. On other customer it's perfectly fine.

    I have a indentical modification for project invoices and there is no issue with any customer. Also this modification runs for like a year already and there wan't any problem with it till now.

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

    If it fails inside getAttachmentStream() (I don't see either addAttachment or getattachment in your code) and not in the code you showed above, then debug the content of getAttachmentStream() to see where things go wrong.

  • RadekM Profile Picture
    172 on at

    Well this is like the whole code needed here. Above it I only look for packingslip and the docuref.

    After debug of getAttachmentStream() it throw error on  return act.getStream(_docuRef);

    The same error as above mentioned.

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

    You're still not looking at where the exception gets raised.

    If i'is thrown in act.getStream(), then look inside act.getStream(), obviously. Or just look as the StackTrace property of the exception.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans