How do I handle an AccessViolationException  
Author Message
JLombela





PostPosted: Visual C# General, How do I handle an AccessViolationException Top

Hi,

My name is John and I am new to this forum. I have just created a little application that downloads documents from a CRM application called Maximizer (www.maximizer.com). These documents can be any kind of document, from email with embedded attachments to word, pdf, etc. Maximizer provides a set of API in a DLL format that allows developers to manipulate the application and retrieve dta from its SQL backend. The code simply extracts a very specific type of document: Email Message and with theri attachments. The probleme lies within the Download method of the oLetters instance. This method takes two arguments Download(string targetPath, out object downloadedFileName).

When I use the method below without the main application, it does what it is supposed to do, but if during the process, I try to move away from the running application and do something else, such as a simple click anywhere else on the screen, the application stops if I am running it in debug mode and stops on the program.cs file on the Main() method of the application, or just freezes if I run the .exe and shows the main dialog box asking me to report the error to Microsoft. Whenever comment out the portion of the code containing the oLetters.Download(Location, out doc) the application does not stop,of course nothing gets downloaded. Can anyone please HELP Its been three weeks now that I have struggled alone to get this thing right. Please check the code below...:

public static void EmailDocument(MaxHost oMaHost, string cn, string Location, ref int Count, ref int xFeedback)

{

List<DocumentInfo> nDocList = new List<DocumentInfo>();

nDocList = Logic.Document.GetAddressBookWithEmailOutlookItems(cn);

Count = nDocList.Count;

MaAccessLib.Letters oLetters = (MaAccessLib.Letters)oMaHost.CreateObject("Letters");

int i = 1;

try

{

foreach (DocumentInfo d in nDocList)

{

object doc = new object();

oLetters.Clear();

oLetters.Client_Id = d.Client_Id;

oLetters.Contact_Number = d.Contact_Number;

oLetters.Description = d.Description;

oLetters.Select(1);

if (oLetters.Download(Location, out doc))

{

d.File_Name = d.Description.Trim().Replace(' ', '_');

d.File_Name = d.Description.Trim().Replace('/', '_');

char[] chars = d.File_Name.ToCharArray();

d.File_Name = "";

string s = "";

foreach (char c in chars)

{

s = c.ToString();

if (c == ' ') s = "_";

if (c == '/') s = "_";

if (c == ':') s = "_";

if (c == '\\') s = "_";

d.File_Name += s;

}

d.File_Name = d.File_Name.Trim() + ".msg";

string IntialFile = Location + + d.File_Name;

string DestinationFile = Location + + d.Sequence + "_" + d.Client_Id + "_" + d.Contact_Number + "_" + d.File_Name;

if (File.Exists(IntialFile))

{

File.Copy(IntialFile, DestinationFile, true);

File.Delete(IntialFile);

}

}

oLetters.EndSelect();

xFeedback = i;

i++;

}

oLetters = null;

nDocList = null;

}

catch (IOException) { }

catch (COMException) { }

}



Visual C#20  
 
 
frederikm





PostPosted: Visual C# General, How do I handle an AccessViolationException Top

Hi

dumb question, but have you tried to put the method call in a try catch block to catch the specific exception

could you post that exception, and any innerexceptions