Archived Forum Post

Index of archived forum posts

Question:

Unhandled Exception with Email.LoadXML

Sep 06 '17 at 22:45

Hi,

I am experiencing an unhandled exception when attempting to load an email from an XML file, but only when the file in question does not contain a complete XML email, for example an empty or corrupt file.

I have the following:

Try
    Dim email as New Email
    If email.LoadXml(sgFile) Then
        'Email successfully loaded, do stuff
    Else
        'Write failure to log file...
    End If

Catch ex As Exception
    'Write error to log file...
End Try

My error handler does not trap the exception and the program terminates unexpectedly. In the system Event Log I see the following 2 events recorded:

  1. Application Error

    Faulting application name: MyProgram.exe, version: 1.1.10.0, time stamp: 0x59ad1431

    Faulting module name: ChilkatDotNet46.dll, version: 9.5.0.65, time stamp: 0x58654057

    Exception code: 0xc0000005

    Fault offset: 0x00000000003adeaa

    Faulting process id: 0x1f44

    Faulting application start time: 0x01d3255b21bb005e

    Faulting application path: C:Program Files (x86)MyMyProgram.exe

    Faulting module path: C:Program Files (x86)MyChilkatDotNet46.dll

    Report Id: 73e25f00-914e-11e7-80eb-00163e57b274

    Faulting package full name:

    Faulting package-relative application ID:

  2. .Net Runtime

    Application: MyProgram.exe

    Framework Version: v4.0.30319

    Description: The process was terminated due to an unhandled exception.

    Exception Info: System.AccessViolationException

    at <module>.ClsEmail.LoadXml(ClsEmail, XString)

    at Chilkat.Email.LoadXml(System.String)

    at MyProgram.MyProgram.MailChecker_ProcessFromXML(Boolean, Boolean ByRef)

    at MyProgram.MyProgram.ImportTimer_Callback(System.Object, System.Timers.ElapsedEventArgs)

    at System.Timers.Timer.MyTimerCallback(System.Object)

    at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)

    at System.Threading.TimerQueueTimer.CallCallback()

    at System.Threading.TimerQueueTimer.Fire()

    at System.Threading.TimerQueue.FireNextTimers()

Is there any way I can prevent this from happening?


Accepted Answer

Here are new builds with the fix:

https://chilkatdownload.com/prerelease/chilkatdotnet46-9.5.0-win32-245.zip
https://chilkatdownload.com/prerelease/chilkatdotnet46-9.5.0-x64-246.zip
https://chilkatdownload.com/prerelease/chilkatdotnet46-vs2017-9.5.0-win32-247.zip
https://chilkatdownload.com/prerelease/chilkatdotnet46-vs2017-9.5.0-x64-248.zip


Answer

Thanks... I'm very sorry for my mistake -- I was thinking you were talking about Xml.LoadXml (not Email.LoadXml). I can't believe I missed what's so clearly stated in both the title and the post. Sorry about that.. I'll re-test.


Answer

Thanks! I found and fixed the problem. I'll create a new build for you..


Answer

Thanks, I'd need to reproduce the problem to find the cause. If you can, send the input file to support@chilkatsoft.com (in a zipped attachment).


Answer

9 don't have access to the files right now, but the last one to cause the error was an empty 0 byte file.


Answer

I wasn't able to reproduce the problem. I created an empty file and then called LoadXml(emptyFilePath) and LoadXmlFile(emptyFilePath), and both did not crash, and both returned false to indicate failure.

By the way... you would pass a file path to LoadXmlFile, and pass actual XML text to LoadXml (you don't pass a file path to LoadXml).

I tested with v9.5.0.69, which was recently released, but I don't recall fixing anything related to what you described..


Answer

Thanks. I'll double check my calls when I'm back at work tomorrow and post an update her


Answer

Hi Chilkat,

I have checked my code, and can confirm I am calling Email.LoadXml(), passing it the path the of XML file. You said in comment above that LoadXml is expecting a string containing XML, but according to the API Reference docs here, https://www.chilkatsoft.com/refdoc/vbnetEmailRef.html, I think I am calling it right:

Function LoadXml(ByVal xmlPath As String) As Boolean

Loads an email with the contents of an XML email file.

Returns True for success, False for failure.

Function LoadXmlString(ByVal xmlStr As String) As Boolean

Loads an email from an XML string (previously obtained by calling the

GetXml method). The contents of the calling email object are erased and replaced with the email contained within the XML string.

Returns True for success, False for failure.