SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

AccessViolationException Error

Last post 01-23-2009 3:29 PM by TommyFive. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-26-2006 4:11 AM

    AccessViolationException Error

    Hi i have install the libusb-win32 and i am trying to get a driver for the Microsoft Fingerprint Reader. However when i download SharpUSBLib and run the demo.exe that is the found that i get.

     

    System.AccessViolationException was unhandled
      Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
      Source="ICSharpCode.USBlib"
      StackTrace:
           at ICSharpCode.USBlib.Internal.NativeMethods.usb_open(usb_device dev)
           at ICSharpCode.USBlib.Device..ctor(Descriptor descriptor)
           at ICSharpCode.USBlib.Descriptor.OpenDevice()

     

    I run the demo.exe in debug mode using Visual Studio and found that. 

         libusb0.dll!100032da()     
         [Frames below may be incorrect and/or missing, no symbols loaded for libusb0.dll]    
         ntdll.dll!7c910f46()     
         mscorwks.dll!79e74753()     
         mscorwks.dll!79e783e6()     
         mscorwks.dll!79e7c1d7()     
         mscorwks.dll!79e7c1c5()     

     

    Is there anything to do iwth ntdll.dll?  What can i do in this case?

    Thanks you very much for answer my question.

    Best regard

    Maverick 

     


     
     

     


       

    Filed under:
  • 01-23-2007 7:23 AM In reply to

    • usha
    • Not Ranked
    • Joined on 01-23-2007
    • Posts 2

    Re: AccessViolationException Error

    hai i'm also facing the same problem..with libusb... since i'm working in vc++ ,i'm getting runtime error as

     C:\WINNT\system32\ntdll.dll', no matching symbolic information found.
    Loaded 'C:\WINNT\system32\KERNEL32.DLL', no matching symbolic information found.

    if u could suggest me the way what u've done with ur error,it would b gr8!!!

    thanks in advance!!!!!! 

  • 02-18-2008 9:02 AM In reply to

    Re: AccessViolationException Error

    hello usha,

     

    yesterday i started on usb developing with #usblib and i had the same problem.

    Good news for you: I have fixed the problem.

     

    I've contacted Mike, that i want to take over the project.

    So may be in a couple of days i can release a new version.

     

    Greetings 

  • 02-18-2008 6:26 PM In reply to

    Re: AccessViolationException Error

    I have been using ICSharpCode.USBLib for about a year on Windows XP with no problem and ran into similar issue once I switched over to Vista. Precisely, AccessViolationException is thrown from .NET marshaling code after the call to usb_get_busses() function in libusb0. I started deeper exploration of this issue yesterday but could not get it fixed yet.

    Best regards,

    Alexei Adadurov

  • 02-19-2008 11:34 AM In reply to

    Re: AccessViolationException Error

    Well, it seems that I ran in another issue, not this one. :-)

    I managed to fix it last night so if someone needs the patch that makes it work on both Window XP and Windows Vista -- just contact me.

  • 03-03-2008 7:40 AM In reply to

    • Bill Farrow
    • Not Ranked
    • Joined on 03-03-2008
    • Melbourne, Australia
    • Posts 1

    Re: AccessViolationException Error

    Let me know if you get access to the project files.  In the mean time here is my patch to get things working on Linux.  I haven't got around to fixing this for Win32.

    diff -urb SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Bus.cs SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Bus.cs
    --- SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Bus.cs 2004-12-08 09:20:16.000000000 +1100
    +++ SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Bus.cs 2008-03-03 17:32:13.000000000 +1100
    @@ -6,6 +6,7 @@
    //
    using System;
    using ICSharpCode.USBlib.Internal;
    +using System.Runtime.InteropServices;

    namespace ICSharpCode.USBlib
    {
    @@ -23,15 +24,16 @@
    NativeMethods.usb_init();
    int rc = NativeMethods.usb_find_busses();
    if (rc <= 0) {
    - throw new MethodCallUsbException("usb_find_busses", rc);
    + //throw new MethodCallUsbException("usb_find_busses", rc);
    }

    rc = NativeMethods.usb_find_devices();
    if (rc <= 0) {
    - throw new MethodCallUsbException("usb_find_devices", rc);
    + //throw new MethodCallUsbException("usb_find_devices", rc);
    }

    - for (usb_bus bus = NativeMethods.usb_get_busses(); bus != null; bus = bus.Next) {
    + usb_bus root_bus = (usb_bus)Marshal.PtrToStructure(NativeMethods.usb_get_busses(), typeof(usb_bus));
    + for (usb_bus bus = root_bus; bus != null; bus = bus.Next) {
    busCollection.Add(new Bus(bus));
    }
    return busCollection;
    @@ -65,5 +67,9 @@
    {
    return String.Format("[Bus: DirectoryName = {0}]", DirectoryName);
    }
    +
    + public string GetLastUsbError() {
    + return NativeMethods.usb_strerror();
    + }
    }
    }
    diff -urb SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Descriptor.cs SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Descriptor.cs
    --- SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Descriptor.cs 2004-12-08 09:20:12.000000000 +1100
    +++ SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Descriptor.cs 2008-03-03 17:34:27.000000000 +1100
    @@ -13,7 +13,7 @@
    /// /// Description of Descriptor. /// - public class Descriptor + public class Descriptor : IEquatable { usb_device nativeDevice; @@ -73,5 +73,14 @@ DeviceClass ); } + + public bool Equals(Descriptor other) + { + return (this.DescriptorType == other.DescriptorType) + && (this.DeviceClass == other.DeviceClass) + && (this.FileName == other.FileName) + && (this.ProductId == other.ProductId) + && (this.VendorId == other.VendorId); + } } } diff -urb SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Device.cs SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Device.cs --- SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Device.cs 2004-12-08 09:20:12.000000000 +1100 +++ SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Device.cs 2008-03-03 17:26:24.000000000 +1100 @@ -89,21 +89,17 @@ if (this.deviceHandle == IntPtr.Zero) { throw new UsbException("Can't open device."); } - /* - int rc = NativeMethods.usb_set_configuration(deviceHandle, 1); - if (rc < 0) { - throw new MethodCallUsbException("usb_set_configuration", rc); - } - rc = NativeMethods.usb_claim_interface(deviceHandle, 0); - if (rc < 0) { - throw new MethodCallUsbException("usb_claim_interface", rc); - } - rc = NativeMethods.usb_set_altinterface(deviceHandle, 0); - if (rc < 0) { - throw new MethodCallUsbException("usb_set_altinterface", rc); - }*/ + int rc; + int retries = 4; + while (((rc = NativeMethods.usb_claim_interface(this.deviceHandle, 0)) < 0) && (retries-- > 0)) { + Console.WriteLine("Attempting to claim interface: rc = " + rc); + rc = NativeMethods.usb_detach_kernel_driver_np(this.deviceHandle, 0); + Console.WriteLine("Attempting to detach kernel driver: rc = " + rc); + } + if (rc < 0) + throw new MethodCallUsbException("usb_claim_interface", rc); } void CheckDeviceOpen() @@ -125,16 +121,16 @@ NativeMethods.usb_bulk_read(deviceHandle, endpoint, bytes, timeout); } - public void InterruptWrite(int endpoint, byte[ bytes) + public int InterruptWrite(int endpoint, byte[ bytes) { CheckDeviceOpen(); - NativeMethods.usb_interrupt_write(deviceHandle, endpoint, bytes, timeout); + return NativeMethods.usb_interrupt_write(deviceHandle, endpoint, bytes, timeout); } - public void InterruptRead(int endpoint, byte[ bytes) + public int InterruptRead(int endpoint, byte[ bytes) { CheckDeviceOpen(); - NativeMethods.usb_interrupt_read(deviceHandle, endpoint, bytes, timeout); + return NativeMethods.usb_interrupt_read(deviceHandle, endpoint, bytes, timeout); } public void SendControlMessage(int requestType, int request, int val, byte[ bytes) diff -urb SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Internal/NativeCode.cs SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Internal/NativeCode.cs --- SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/Internal/NativeCode.cs 2004-12-08 09:20:12.000000000 +1100 +++ SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/Internal/NativeCode.cs 2008-03-03 17:29:06.000000000 +1100 @@ -329,6 +329,10 @@ public IntPtr dev = IntPtr.Zero; // Darwin support + public byte devnum; + public byte num_children; + public IntPtr children = IntPtr.Zero; + public override string ToString() { return String.Format("[usb_device: filename={0}, next={1}, prev={2}, bus={3}, descriptor={4}, config={5}, dev={6}]", @@ -395,6 +399,7 @@ public IntPtr devices= IntPtr.Zero; public uint location = 0; + public IntPtr root_dev = IntPtr.Zero; public usb_bus Next { get { @@ -424,12 +429,13 @@ public override string ToString() { - return String.Format("[usb_bus: dirname={0}, next={1}, prev={2}, Devices={3}, location={4}]", + return String.Format("[usb_bus: dirname={0}, next={1}, prev={2}, Devices={3}, location={4}, root_dev={5}]", dirname, next, prev, Devices, - location); + location,
    + root_dev);
    }
    };

    @@ -578,9 +584,12 @@
    public static extern int usb_find_devices();

    [DllImport(LIBUSB_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION, ExactSpelling = true), SuppressUnmanagedCodeSecurity]
    - public static extern usb_device usb_device(IntPtr dev);
    + public static extern IntPtr usb_device(IntPtr dev);
    +
    + [DllImport(LIBUSB_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION, ExactSpelling = true), SuppressUnmanagedCodeSecurity]
    + public static extern IntPtr usb_get_busses();

    [DllImport(LIBUSB_NATIVE_LIBRARY, CallingConvention = CALLING_CONVENTION, ExactSpelling = true), SuppressUnmanagedCodeSecurity]
    - public static extern usb_bus usb_get_busses();
    + public static extern int usb_detach_kernel_driver_np(IntPtr dev, int interfaceNum);
    }
    }
    diff -urb SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/USBException.cs SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/USBException.cs
    --- SharpUSBlib20041208.Orig/SharpUSBlib/src/ICSharpCode.USBlib/USB/USBException.cs 2004-12-08 09:20:12.000000000 +1100
    +++ SharpUSBlib20041208/SharpUSBlib/src/ICSharpCode.USBlib/USB/USBException.cs 2008-03-03 17:26:39.000000000 +1100
    @@ -67,7 +67,7 @@
    {
    }

    - public MethodCallUsbException(string method, int returnCode) : base(NativeMethods.usb_strerror())
    + public MethodCallUsbException(string method, int returnCode)// : base(NativeMethods.usb_strerror())
    {
    this.method = method;
    this.returnCode = returnCode;

  • 01-23-2009 3:29 PM In reply to

    Re: AccessViolationException Error

     I found the time to update the project.

     

    You can find it under: http://tommyfive.untied.de/usblib/

     

    Greetings from Germany

Page 1 of 1 (7 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.