none
System.AccessViolationException in VB2013 RRS feed

  • Question

  •  Hi,

        I need to send specific amount of bits to a device and the Function requires that I provide the Bit Count and the Byte Count. Note that you can not always get exact match of the Bit Count to the Byte Count because Bytes are in 8-bits. So I used the following calculations as an example

    NumberOfBits = 200

    NumberOFBytes = NumberOfBits / 8 + 1 'Note this translates into 26 Bytes total

    When I send these parameters to the function I get error "System.AccessViolationException" . This method worked fine in VB6 and and in Python. I reduced the byte count to be 25 and it still gave the same error. Howere if I reduce it to 24 the then the function is executed but get error back from the function saying "NUMBER_BYTES_TOO_SMALL".  

    Any solutions ???

    Thursday, August 7, 2014 5:52 PM

Answers

  • Hello,

    >> I need to send specific amount of bits to a device and the Function requires that I provide the Bit Count and the Byte Count.

    I am confused which function you are working with, is it a function under one .NET Framework dll?

    >> When I send these parameters to the function I get error "System.AccessViolationException" .

    This error usually occurs when an access violation occurs in unmanaged or unsafe code when the code attempts to read or write to memory that has not been allocated, or to which it does not have access.

    Starting with the .NET Framework 4, AccessViolationException exceptions thrown by the common language runtime are not handled by the catch statement in a structured exception handler if the exception occurs outside of the memory reserved by the common language runtime.

    To handle such an AccessViolationException exception, there are a few ways to get around this:

    1.Add a line to your application's config file under the configuration/runtime element: <legacyCorruptedStateExceptionsPolicy enabled="true|false"/>

    2. Apply the HandleProcessCorruptedStateExceptionsAttribute attribute to the method in which the exception is thrown. This change does not affect AccessViolationException exceptions thrown by user code, which can continue to be caught by a catch statement.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, August 8, 2014 8:36 AM
    Moderator