cancel
Showing results for 
Search instead for 
Did you mean: 

Error while Exporting to Email(attempted to read or write protected memory this is often an indication that other memory is corrupt)

Former Member
0 Kudos

Hi All,

I have a piece of code that exports the the report as PDF to email, and I am getting the following error while doing so.

"Attempted to read or write protected memory this is often an indication that other memory is corrupt"

I am using Windows 2008 R2 and windows 7

the problem is happening in the Export function of ReportDocument class.

Sample Code here:

ReportDocument rptDocument = new ReportDocument();

rptDocument.Export()

and I am getting the System.AccessViolationException for this error.

Here are the details of .NET and Crystal version:

.NET version : Crystal Report for .NET Framework 4.0

Crystal Report version : Crystal report for Visual Studio 2010 (SP8)

Any suggestion would be greatly appreciated.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Gallen,

Moved your post to the .NET SDK forum

Do you have Outlook installed?

Try this code, first part is exporting to Exchange folder...

ExchExpOpts.FolderPath = "YourName@Company.com#Inbox"; // Should be an exchange folder...

ExchExpOpts.Profile = "Default Outlook Profile"; //_exchangeProfile; // "MS Exchange Settings"; // "Outlook";

ExchExpOpts.Password = "password";

exportOpts.ExportFormatOptions = PDFExpOpts;

exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.ExchangeFolder;

exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

exportOpts.ExportDestinationOptions = ExchExpOpts;

rpt.Export(exportOpts);

MessageBox.Show("Mail to Exchange folder sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

exportOpts.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail;

exportOpts.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;

exportOpts.ExportFormatOptions = pdfOpts;

mailOpts.MailToList = "Your Name";

mailOpts.MailSubject = "Attached is a PDF file - .net Export test ";

mailOpts.MailSubject = "This is the Subject";

//MailOpts.MailCCList = "John Doe";

mailOpts.UserName = "YourName@Company.com";

mailOpts.Password = "YourPassword";

exportOpts.ExportDestinationOptions = mailOpts;

rpt.Export(exportOpts);

MessageBox.Show("Mail sent Completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

Don

Former Member
0 Kudos

Don,

Thanks for your reply.

//////////////////////////////////This is for ExportToExchange/////////////////////////////////////////////////

I tried the above code for export to exchange, but export to exchange is not working for me. I am getting an exception when I try it. I am getting an "invalid export option" exception. Please find the exception message below. I got this error when I tried to debug.

---------------------------

---------------------------

CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid export options.

   at CrystalDecisions.CrystalReports.Engine.STACaller.Call()

   at CrystalDecisions.CrystalReports.Engine.ExchangeMessage.Send()

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportStreamToExchange(Stream stream, ExchangeFolderDestinationOptions options, String name)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)

   at SampleApplication.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\css103471\Documents\Visual Studio 2005\Projects\SampleApplication\SampleApplication\Form1.cs:line 59

---------------------------

OK

---------------------------

ExchExpOpts.FolderPath = "YourName@Company.com#Inbox"; // Should be an exchange folder...

ExchExpOpts.Profile = "Default Outlook Profile"; //_exchangeProfile; // "MS Exchange Settings"; // "Outlook";

I think the problem might be in the above two statements, but I am not sure. I dont know the exact string format for the above statements. I have copied my code here for your reference.

ExportOptions exportOpts = new ExportOptions();

            ExchangeFolderDestinationOptions exchangeOpts = ExportOptions.CreateExchangeFolderDestinationOptions();

    

            exchangeOpts.DestinationType = ExchangeDestinationType.ExchangePostDocMessage;

            exchangeOpts.FolderPath = "mailto: myname@company.com@Inbox"; ###Don't know the exact format for this path.

            exchangeOpts.Profile = "myname@company.com"; # I also tried by giving the profile name which is just "Outlook". //From control panel selected Mail(32 bit)->Mail Setup - Outlook window->Show Profiles option, in the resulting window had only "Outlook" listed as profile name

            exchangeOpts.Password = "*********";

         

            exportOpts.ExportDestinationOptions = exchangeOpts;

    

            exportOpts.ExportDestinationType = ExportDestinationType.ExchangeFolder;

            exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;

         

            ReportDocument rd = new ReportDocument();

            rd.Load("C:\\Users\\css103471\\Desktop\\ardinvo.rpt");

            rd.Export(exportOpts);

//////////////////////////////////This is for Export to Email///////////////////////////////

I tried to the ExportToEmail code in windows 7 and worked without any problem, and I tried the same in windows 2008 R2, but got an exception. I have pasted the exception below.

---------------------------

---------------------------

CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid export options.

   at CrystalDecisions.CrystalReports.Engine.STACaller.Call()

   at CrystalDecisions.CrystalReports.Engine.MAPIMessage.Send()

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportStreamToMAPI(Stream stream, MicrosoftMailDestinationOptions options, String name)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)

   at SampleApplication.Form1.button1_Click(Object sender, EventArgs e)

---------------------------

OK 

---------------------------

Also pasted the code I used here.

ReportDocument rptDocument = new ReportDocument();

            try

            {

            rptDocument.Load("C:\\Users\\Administrator\\Desktop\\ardinvo.rpt");

          

              

            MicrosoftMailDestinationOptions mailOptions = new MicrosoftMailDestinationOptions();

            ExportOptions exportOptions = new ExportOptions();

            mailOptions.MailToList = "myname@company.com";

            mailOptions.MailCCList = "myname@company.com";

            mailOptions.MailSubject = "This is test mail";

            mailOptions.MailMessage = "This is test message";

          

            mailOptions.Password = "***********";     

            mailOptions.UserName = "Administrator";

          

            exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

            exportOptions.ExportDestinationType = ExportDestinationType.MicrosoftMail;

            exportOptions.ExportDestinationOptions = mailOptions;

          

                MessageBox.Show("Before Exporting");

                rptDocument.Export(exportOptions);

                MessageBox.Show("After Exporting");

                rptDocument.Close();

                rptDocument.Dispose();

                MessageBox.Show("Closed and Disposed");

            }

            catch (System.AccessViolationException ave)

            {

                MessageBox.Show("Exception Inside catch block(AccessViolationException) : ", ave.ToString());

                rptDocument.Close();

                rptDocument.Dispose();

                MessageBox.Show("Exception Inside catch block(AccessViolationException) : Closed and Disposed");

            }

            catch (System.Exception eVal)

            {

                MessageBox.Show(eVal.ToString());

                rptDocument.Close();

                rptDocument.Dispose();

                MessageBox.Show("Closed and Disposed");              

            }

I tried this code in Win 7 , it is working fine. But I tried the same in Win2008 R2 got the exception.

I am using Windows 2008 R2 in virtual machine.

Please help and thanks in advance.

0 Kudos

Use the pound sign and not the at sign.

Also, Outlook must be installed locally

Don

Former Member
0 Kudos

Hi Don,

This is regarding the sample email application. Like I had mentioned before, the sample email application is working fine and is sending mail without any problem.

It is working fine Windows 2008 R2 server. But However my Original application not working in Windows 2008 R2 server PC. Now I am don't understand

why my original application is throwing the exception while the sample application is working fine.

Here I have posted my sample application's source code:

--------------------------------------------------------

ReportDocument rptDocument = new ReportDocument();

try

{

rptDocument.Load("C:\\Users\\Administrator\\Desktop\\ardinvo.rpt");//virtual machine

MicrosoftMailDestinationOptions mailOptions = new MicrosoftMailDestinationOptions();

ExportOptions exportOptions = new ExportOptions();

mailOptions.MailToList = "myname@company.com";

mailOptions.MailSubject = "This is test mail";

mailOptions.MailMessage = "This is test message";

mailOptions.Password = "password!23";

mailOptions.UserName = "Administrator";

exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

exportOptions.ExportDestinationType = ExportDestinationType.MicrosoftMail;

exportOptions.ExportDestinationOptions = mailOptions;

  MessageBox.Show("Before Exporting");

  rptDocument.Export(exportOptions);

  MessageBox.Show("After Exporting");

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Closed and Disposed:Success");

}

catch (System.AccessViolationException ave)

{

  MessageBox.Show("Exception Inside catch block(AccessViolationException) : ", ave.ToString());

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Exception Inside catch block(AccessViolationException) : Closed and Disposed");

}

catch (System.Exception eVal)

{

  MessageBox.Show(eVal.ToString());

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Closed and Disposed");               

}

This above sample application is working fine and sends mail without any problem in Windows 2008 R2 server.

Environment Details for the above application:

Executing OS : Windows 2008 R2 server

I developed this application in Win 7 OS and running the release exe in windows 2008 R2 server.

Development Environment:

OS : Win 7 64 bit

IDE : Visutal studio 2010.


But my Original application is not working in the Windows 2008 R2 server. I keep getting the below exception.

"Attempted to read or write protected memory this is often an indication that other memory is corrupt"

One thing I forgot to mention is, using my Original application I send emails to multiple customers at the single click of a button. Here mail is sent first time,

from second time onward I am getting the above exception.

Ex: If I configure my application to send emails to five customers and click send, it will send email for the first customers only. For the remaining four customers,

I will get the above exception.

Environment Details for the Original application:

Executing OS: Windows 2008 R2 Server

Development Environment:

OS : Win 7 64 bit

IDE : Visutal studio 2005.


Please help solve it.

Thanks.

0 Kudos

Hi,

Well if the test app works then no point in debugging that.

All I can suggest is you install Visual Studio on a test Windows 2008 Server and run in debug mode so you get more details one what the exception is about an why.

DebugDiag may give you the dll it's crashing but won't fix your code.

ProcessMonitor should help also, look for access denied errors.

Don

Former Member
0 Kudos

Hi Don,

Yes I will install Visual Studio on the test environment and will try to debug that.

I tried one more thing. i.e. I just looped the above code for 5 iterations, and to my amazement, I was able to reproduce the error. In the first iteration the mail was sent without any problem, but from second time onward I am getting the AccessViolationException with the same error string.

Here I have posted my sample code and the complete error string.

SourCode:

-------------

for(int i = 0; i < 5; i++)

{

ReportDocument rptDocument = new ReportDocument();

try

{

rptDocument.Load("C:\\Users\\Administrator\\Desktop\\ardinvo.rpt");//virtual machine

MicrosoftMailDestinationOptions mailOptions = new MicrosoftMailDestinationOptions();

ExportOptions exportOptions = new ExportOptions();

mailOptions.MailToList = "myname@company.com";

mailOptions.MailSubject = "This is test mail";

mailOptions.MailMessage = "This is test message";

mailOptions.Password = "password!23";

mailOptions.UserName = "Administrator";

exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

exportOptions.ExportDestinationType = ExportDestinationType.MicrosoftMail;

exportOptions.ExportDestinationOptions = mailOptions;

  MessageBox.Show("Before Exporting");

  rptDocument.Export(exportOptions);

  MessageBox.Show("After Exporting");

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Closed and Disposed:Success");

}

catch (System.AccessViolationException ave)

{

  MessageBox.Show("Exception Inside catch block(AccessViolationException) : ", ave.ToString());

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Exception Inside catch block(AccessViolationException) : Closed and Disposed");

}

catch (System.Exception eVal)

{

  MessageBox.Show(eVal.ToString());

  rptDocument.Close();

  rptDocument.Dispose();

  MessageBox.Show("Closed and Disposed");               

}

}

Exception String:

---------------------------

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

   at CrystalDecisions.CrystalReports.Engine.STACaller.Call()

   at CrystalDecisions.CrystalReports.Engine.MAPIMessage.Send()

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportStreamToMAPI(Stream stream, MicrosoftMailDestinationOptions options, String name)

   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)

   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)

   at SampleApplication.Form1.button1_Click(Object sender, EventArgs e)

---------------------------

OK  

---------------------------

the crash happens exactly at the "rptDocument.Export(exportOptions)". From the call stack it seems, there is a problem in the MAPI code. But I am not sure.

I thought posting this information would help you. I mean time I am also going to google using this exception message.

Thanks for your response.

Former Member
0 Kudos

Don,

Did you get a chance to see my previous post. Do you have any suggestions for me?

Does this call stack gives you any clue?

Would greatly appreciate any suggestions.

Thanks.

0 Kudos

Hi Gallen,

Off on holidays...

Add this to your try:

CrystalDecisions.CrystalReports.Engine.ReportDocument rptDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

When you Dispose of the rptDocument you are removing it's reference so you need to instantiate it again.

So either don't Dispose or declare it in the loop.

Don

Former Member
0 Kudos

Hi Don,

I have created a sample C# application using Visual Studio 2005 to send email using the crystal's API's

I am using the ReportDocument's Export function to send email.

And I am using these crystal related namespaces's

using System.Runtime.InteropServices;

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

And for these namespaces I have to use these reference DLL's

CrystalDecisions.CrystalReports.Engine

CrystalDecisions.ReportAppServer.ClientDoc

CrystalDecisions.ReportAppServer.DataDefModel

CrystalDecisions.Shared

CrystalDecisions.Windows.Forms

Now my PC has three different versions of the above DLLs,

They are:

10.2.3600.0

10.5.3700.0

13.0.2000.0

I am able to include 10.2.3600.0 and 10.5.3600.0 in VS 2005,but could not do the same for 13.0.2000.0.

But I am able to include 13.0.XXXX.X version from VS 2010.

I want to use the 13.0.XXXX.X version in VS 2005.

Can you help me how to do that?

Thanks in Advance.

Answers (0)