Unexpected exception while downloading from Canon

Post Reply
bvanderwkc
Posts: 3
Joined: Thu Apr 26, 2018 5:59 pm

Unexpected exception while downloading from Canon

Post by bvanderwkc » Thu Apr 26, 2018 6:13 pm

I am having an issue that is totally kicking my butt. While capturing photos every few seconds from a Canon camera, less than 5% of the time we are seeing the following exception:

Code: Select all

Unexpected exception while downloading.
Object reference not set to an instance of an object.
   at Canon.Eos.Framework.Internal.EosImageTransporter.Download(IntPtr directoryItem, UInt64 size, IntPtr stream) in C:\Users\bvanderw\Dropbox\Documents\Visual Studio 2017\Projects\kOS\kos-win\DigiCam\Canon.Eos.Framework\Internal\EosImageTransporter.cs:line 62
   at Canon.Eos.Framework.Internal.EosImageTransporter.Transport(IntPtr directoryItem, UInt64 size, IntPtr stream, Boolean destroyStream) in C:\Users\bvanderw\Dropbox\Documents\Visual Studio 2017\Projects\kOS\kos-win\DigiCam\Canon.Eos.Framework\Internal\EosImageTransporter.cs:line 74
   at Canon.Eos.Framework.Internal.EosImageTransporter.TransportAsFileName(IntPtr directoryItem, String imagePath, IntPtr context) in C:\Users\bvanderw\Dropbox\Documents\Visual Studio 2017\Projects\kOS\kos-win\DigiCam\Canon.Eos.Framework\Internal\EosImageTransporter.cs:line 101
   at CameraControl.Devices.Canon.CanonSDKBase.TransferFile(Object o, String filename)
   at Canon.Eos.Framework.Internal.SDK.Edsdk.EdsDownload(IntPtr inDirItemRef, UInt64 inReadSize, IntPtr outStream)
   at Canon.Eos.Framework.Internal.EosImageTransporter.Download(IntPtr directoryItem, UInt64 size, IntPtr stream) in C:\Users\bvanderw\Dropbox\Documents\Visual Studio 2017\Projects\kOS\kos-win\DigiCam\Canon.Eos.Framework\Internal\EosImageTransporter.cs:line 53
As you can see, it is failing at a call to the Canon SDK, so I am at a loss how to address this. We have seen this on two computers using different Canon cameras.

I have tried to duplicate this using the example program, but can't make it fail. Anyone else see anything like this? Any suggestions on what I might try or an alternative way of doing this?

Bruce

Unexpected exception while downloading from Canon

Advertisment
 

bvanderwkc
Posts: 3
Joined: Thu Apr 26, 2018 5:59 pm

Re: Unexpected exception while downloading from Canon

Post by bvanderwkc » Mon Apr 30, 2018 1:10 am

This does appear to be an issue with memory allocation. If I surround the call to CanonSDKBase.TransferFile with GC.TryStartNoGCRegion and GC.EndNoGCRegion, the problem completely disappears.

admin
Site Admin
Posts: 90
Joined: Tue Sep 15, 2015 8:33 pm

Re: Unexpected exception while downloading from Canon

Post by admin » Thu May 03, 2018 9:41 pm

Thank for the feedback. I meet this issue time to time too, but i don't find any good solution for it, until now :)

Mosanec
Posts: 5
Joined: Thu Apr 12, 2018 8:00 am

Re: Unexpected exception while downloading from Canon

Post by Mosanec » Thu May 03, 2018 11:56 pm

hello
How do you set those properties and where in the code please?
regards

bvanderwkc
Posts: 3
Joined: Thu Apr 26, 2018 5:59 pm

Re: Unexpected exception while downloading from Canon

Post by bvanderwkc » Fri May 04, 2018 12:38 pm

Call SuspendGarbageCollection before and ResumeGarbageCollection after the call to CanonSDKBase.TransferFile.

(Replace the calls to LogInfo and LogInternalException with your own logging.)

Code: Select all

    private void SuspendGarbageCollection()
    {
      try
      {
        var oneMB = 1024 * 1024;
        LogInfo(GC.TryStartNoGCRegion(5 * oneMB) ? "GC suspended" : "Unable to suspend GC");
      }
      catch (Exception ex)
      {
        LogInternalException("TryStartNoGCRegion", ex);
      }
    }

    private void ResumeGarbageCollection()
    {
      try
      {
        GC.EndNoGCRegion();
      }
      catch (Exception ex)
      {
        LogInternalException("EndNoGCRegion", ex);
      }
    }
 


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest