Archived Forum Post

Index of archived forum posts

Question:

System.AccessViolationException in DeleteBundle

Apr 13 '15 at 15:07

Hello,

using the latest release and very always gets

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at ClsMailMan.DeleteBundle(ClsMailMan , ClsEmailBundle , ProgressEvent* )
at Chilkat.MailMan.DeleteBundle(EmailBundle bundle)

debug file:

DeleteBundle:
    DllDate: Mar  9 2015
    ChilkatVersion: 9.5.0.48
    UnlockPrefix: xxx
    Username: xxx
    Architecture: Little Endian; 64-bit
    Language: .NET 4.5 / x64
    VerboseLogging: 1
    PopCmdSent: DELE 382
    sendCommand: Elapsed time: 0 millisec
    PopCmdResp: +OK Deleted.
    getOneLineResponse: Elapsed time: 0 millisec
    message successfully marked for delete
    PopCmdSent: DELE 383
    sendCommand: Elapsed time: 0 millisec
    PopCmdResp: +OK Deleted.
    getOneLineResponse: Elapsed time: 0 millisec
    message successfully marked for delete
    PopCmdSent: DELE 384
    sendCommand: Elapsed time: 0 millisec
    PopCmdResp: +OK Deleted.
    getOneLineResponse: Elapsed time: 0 millisec
    message successfully marked for delete
    PopCmdSent: DELE 385
    sendCommand: Elapsed time: 0 millisec
    PopCmdResp: +OK Deleted.
    getOneLineResponse: Elapsed time: 0 millisec
    message successfully marked for delete

Answer

Please check to see if this new build fixes the problem:

32-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-win32.zip

64-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-x64.zip


Answer

Already tested, unfortunatelly not

What is more the same exception is with HttpRequest.RemoveParam too

So far I was using ver 9.4.1.0 with success

After upgrading to newest release many problems with System.AccessViolationException


Answer

The problem with HttpRequest.RemoveParam should've been fixed with the build I just provided you. I suspect it's possible you're not actually using the new build I just provided. Please post the debug log file created via the DebugLogFilePath property (for the DeleteBundle crash).


Answer

RemoveParam looks working good - thanks

Now I recive same error with GetEmail

Email email = bundle.GetEmail(j);

Unhandled Exception: System.AccessViolationException: Attempted to read or write
 protected memory. This is often an indication that other memory is corrupt.
   at ClsEmailBundle.GetEmail(ClsEmailBundle* , Int32 )
   at Chilkat.EmailBundle.GetEmail(Int32 index)
   at MyApp.EmailEngine3.<>c__DisplayClass12.<>c__DisplayClass1
7.<Start>b__9(Int32 j)
   at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass11.<ExecuteSelfReplicating>b_
_10(Object param0)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCo
ntext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

I'm processing bundle (that contains 500 mails) with Parallel.For

Parallel.For(0, bundle.MessageCount,
                            new ParallelOptions {CancellationToken = CTS.Token, MaxDegreeOfParallelism = 50}, j =>
                            {
                                CTS.Token.ThrowIfCancellationRequested();

                                Email email = bundle.GetEmail(j);

That exception is random - for testing I'm processing one account many times

Full log from pop3 session is here: https://www.dropbox.com/s/2hgp7unho0d104s/mail.txt?dl=0


Answer

Thanks! This is much better information. I will work on a fix today..


Answer

Please check to see if this new build fixes the problem:

32-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-win32.zip

64-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-x64.zip


Answer

Hi, so far no problem with mails, but:

Unhandled Exception: System.AccessViolationException: Attempted to read or write
 protected memory. This is often an indication that other memory is corrupt.
   at ClsHttp.SynchronousRequest(ClsHttp* , XString* , Int32 , Boolean , ClsHttp
Request* , ProgressEvent* )
   at Chilkat.Http.SynchronousRequest(String domain, Int32 port, Boolean ssl, Ht
tpRequest req)
   at MyApp.Submitter.FastEngine.Submit2(String url)
   at CallSite.Target(Closure , CallSite , CodeContext , Object )
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site
, T0 arg0, T1 arg1)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`3.Run(InterpretedFrame
frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 a
rg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
   at simpleseobox.Submitter.EngineRunner.<>c__DisplayClass1f.<>c__DisplayClass3
5.<Run>b__1b(String line, ParallelLoopState loopState, Int64 idx)
   at System.Threading.Tasks.Parallel.<>c__DisplayClass32`2.<PartitionerForEachW
orker>b__30()
   at System.Threading.Tasks.Task.InnerInvokeWithArg(Task childTask)
   at System.Threading.Tasks.Task.<>c__DisplayClass11.<ExecuteSelfReplicating>b_
_10(Object param0)
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionCo
ntext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, C
ontextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.ThreadPoolWorkQueue.Dispatch()

Is there chance to solve AccessViolationException issues with this exception in newest version? Or I need to back to 9.4.1


Answer

Thanks. I would need to see the exact snippet of code that reproduces the problem. It's important to know, for example, if the object is being called in a multi-threaded (parallel) environment. Is the same instance of the Http object called in each thread, or a separate instance? Etc. There's likely an important piece of information I need that isn't being furnished by the stack trace alone.


Answer

Http object isn't shared - there are always new object created per thread

public bool Submit2(string url)
{
     if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
        {
            _uri = new Uri(url);
            _req.Path = _uri.PathAndQuery;
        }
        else
        {
            _uri = _formUri;
        }

        _response = _http.SynchronousRequest(_uri.Host, _uri.Port, _uri.Scheme == Uri.UriSchemeHttps, _req);

and:

    private readonly Http _http = new Http();
    private HttpRequest _req = new HttpRequest();
    private HttpResponse _response;

    public FastEngine()
    {
        bool success = _http.UnlockComponent("");
        if (success != true)
        {
            MessageBox.Show("HTTP Unlock Error");
        }

        _userAgent = ConfigStorage.Instance.GetUserAgent();
        _http.SetRequestHeader("User-Agent", _userAgent);
        _http.CookieDir = "memory";
        _http.SaveCookies = true;
        int readTimeout = Convert.ToInt32(Settings.Default.readTimeout);
        _maxContentLength = Convert.ToInt32(Settings.Default.maxContentLength)*1000;
        _http.ConnectTimeout = Convert.ToInt32(Settings.Default.connectTimeout);
        _validContentTypes = Settings.Default.validContentType.Split('\n');
        _http.ReadTimeout = readTimeout;

        _http.HeartbeatMs = readTimeout*1000/2;
        _http.OnAbortCheck += (sender, args) =>
        {
            if (_abort)
            {
                args.Abort = true;
                _abort = false;
            }
        };

and:

Parallel.ForEach(lines, ConfigStorage.Instance.EngineParallelOptions,
                                    (line, loopState, idx) =>
                                    {
                                        try
                                        {
                                            ConfigStorage.Instance.EngineParallelOptions.CancellationToken
                                                .ThrowIfCancellationRequested();

                                            using (var engine = new FastEngine
                                            {
                                                //here code for filling HttpRequest in engine
                                                engine.Submit2(line);
                                            })

Answer

Try this new build:

32-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-win32.zip
64-bit Download: http://www.chilkatsoft.com/download/preRelease/ChilkatDotNet45-9.5.0-x64.zip

Let me know if this solves it..