GetAsBitmap AccessViolationException

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
Posts: 4
Joined: Fri Aug 06, 2010 2:08 am

GetAsBitmap AccessViolationException

Post by kossman » Mon Sep 20, 2010 8:18 am

I'm using the new version of Vintasoft.Twain.Net, and am having a problem I wasn't having with older versions (e.g. 7.0.0). Running the example TwainSimpleDemo I get an "AccessViolationException was unhandled" in the call:

pictureBox1.Image = _device.AcquiredImages.Last.GetAsBitmap(True)

(in the "Private Sub _device_ImageAcquired(sender As Object, e As ImageAcquiredEventArgs)" function)

The error message is "Attempted to read or write protected memory. This is often an idication that other memory is corrupt"

I've run this many times and it has managed to scan from time to time, but I can't get any pattern as to when it works. It seemed to work once after I scanned in another application so I thought maybe the image buffer in the scanner was locked or not cleared, but with subsequent tests the TwainSimpleDemo failed from the first scan (and all afterwards).

Is anyone else having this problem or knows what it could be?

Here is the exception detail in case that helps at all. I'm using the .net framework 2.0 version and have dotnet framework 3.5 on my computer:

System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length)
at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex, IntPtr destination, Int32 length)
at Vintasoft.Twain.AcquiredImage.(Boolean )
at Vintasoft.Twain.AcquiredImage.GetAsBitmap(Boolean safeBitmap)
at TwainSimpleDemo.MainForm._device_ImageAcquired(Object sender, ImageAcquiredEventArgs e) in C:\Program Files\VintaSoft\VSTwain.NET.7_0\Examples\VS.NET.2008\VB.NET\TwainSimpleDemo\MainForm.vb:line 125
at Vintasoft.Twain.Device.(ImageAcquiredEventArgs )
at Vintasoft.Twain.Device.()
at Vintasoft.Twain.Device.()
at Vintasoft.Twain.DeviceManager.(Message& )
at ..PreFilterMessage(Message& m)
at System.Windows.Forms.Application.ThreadContext.ProcessFilters(MSG& msg, Boolean& modified)
at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TwainSimpleDemo.Program.Main() in C:\Program Files\VintaSoft\VSTwain.NET.7_0\Examples\VS.NET.2008\VB.NET\TwainSimpleDemo\Program.vb:line 14
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Site Admin
Posts: 1647
Joined: Thu Jul 10, 2008 2:21 pm

Re: GetAsBitmap AccessViolationException

Post by Alex » Tue Sep 21, 2010 1:15 pm


What scanner do you have?

Please generate log-file with extended information and send it to

Here is a code snippet that allows you to generate log-file:

Code: Select all

using (DeviceManager deviceManager = new DeviceManager(this))
   deviceManager.Logger = new DeviceManagerLogger(@"x:\vstwain.log", true);
   deviceManager.Logger.LogInfoLevel = LogInfoLevel.Extended;
Best regards, Alexander

Site Admin
Posts: 1647
Joined: Thu Jul 10, 2008 2:21 pm

Re: GetAsBitmap AccessViolationException

Post by Alex » Thu Sep 23, 2010 11:41 am

Hi Colin,

Problem fixed in version Thank you for your help.

Best regards, Alexander

Post Reply