List Info

Thread: how to trouble shoot access violation




how to trouble shoot access violation
user name
2006-08-29 13:15:40
I have a class that returns an image as a public property. I
am
occasionally getting an AccessViolationException.  I am not
sure why,
and I have no idea how to trouble shoot it.  It is a simple
property
that loads an image from a file.  The error message is:

 

"Attempted to read or write protected memory. This is
often an
indication that other memory is corrupt."

 

This happens in the Return Image.... Line in the property
below. The
value of _listenImage is "D:\Projects
.NET\ListeningStation\bin\Application
Customization\Ear.gif"  ... and
the file exists.  Not sure exactly what to do next here.
Thanks.

 

  Public ReadOnly Property ListenImage() As Image

        Get

            If Me._listenImage <> String.Empty Then

                Try

                    Return Image.FromFile(Me._listenImage)

                Catch ex As AccessViolationException

                    Return Nothing

                End Try

            Else

                Return Nothing

            End If

        End Get

    End Property

 

 

Stacey Levine

Lead Technical Architect

Value Music Concepts

825-C Franklin Court

Marietta, GA 30067

678-229-4255

 


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

how to trouble shoot access violation
user name
2006-08-30 07:28:11
Hi Stacey,

Not sure if I can help but,
How often are you calling the property?
It seems each call to the property will create a new Image
instance.
So you might leak memory there...

- One option is to keep track of the image in your class.
- Or make the caller responsible for the image (but in that
case I
would change the property into a function, just to get the
intend
right)


// Ryan

On 8/29/06, Stacey Levine <staceylmusicforasong.com>
wrote:
> I have a class that returns an image as a public
property. I am
> occasionally getting an AccessViolationException.  I am
not sure why,
> and I have no idea how to trouble shoot it.  It is a
simple property
> that loads an image from a file.  The error message is:
>
>
>
> "Attempted to read or write protected memory.
This is often an
> indication that other memory is corrupt."
>
>
>
> This happens in the Return Image.... Line in the
property below. The
> value of _listenImage is "D:\Projects
> .NET\ListeningStation\bin\Application
Customization\Ear.gif"  ... and
> the file exists.  Not sure exactly what to do next
here. Thanks.
>
>
>
>  Public ReadOnly Property ListenImage() As Image
>
>        Get
>
>            If Me._listenImage <> String.Empty
Then
>
>                Try
>
>                    Return
Image.FromFile(Me._listenImage)
>
>                Catch ex As AccessViolationException
>
>                    Return Nothing
>
>                End Try
>
>            Else
>
>                Return Nothing
>
>            End If
>
>        End Get
>
>    End Property
>
>
>
>
>
> Stacey Levine
>
> Lead Technical Architect
>
> Value Music Concepts
>
> 825-C Franklin Court
>
> Marietta, GA 30067
>
> 678-229-4255
>
>
>
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

how to trouble shoot access violation
user name
2006-08-30 16:22:21
It was getting called multiple times.  I changed the way I
was using it
to call it only once.. but I am still not sure why it was
sometimes
getting the error. I ran it against the boundschecker stuff
by Compuware
and it detected no memory leaks. There is no doubt that my
way of doing
it now is *better* with less disk access and probably less
memory.. 

Thanks.
 
Stacey
-----Original Message-----
From: Discussion of writing applications and components
using Visual
Basic .NET [mailto:VBDOTNETDISCUSS.DEVELOP.COM] On
Behalf Of Ryan Heath
Sent: Wednesday, August 30, 2006 3:28 AM
To: VBDOTNETDISCUSS.DEVELOP.COM
Subject: Re: [VBDOTNET] how to trouble shoot access
violation

Hi Stacey,

Not sure if I can help but,
How often are you calling the property?
It seems each call to the property will create a new Image
instance.
So you might leak memory there...

- One option is to keep track of the image in your class.
- Or make the caller responsible for the image (but in that
case I
would change the property into a function, just to get the
intend
right)


// Ryan

On 8/29/06, Stacey Levine <staceylmusicforasong.com>
wrote:
> I have a class that returns an image as a public
property. I am
> occasionally getting an AccessViolationException.  I am
not sure why,
> and I have no idea how to trouble shoot it.  It is a
simple property
> that loads an image from a file.  The error message is:
>
>
>
> "Attempted to read or write protected memory.
This is often an
> indication that other memory is corrupt."
>
>
>
> This happens in the Return Image.... Line in the
property below. The
> value of _listenImage is "D:\Projects
> .NET\ListeningStation\bin\Application
Customization\Ear.gif"  ... and
> the file exists.  Not sure exactly what to do next
here. Thanks.
>
>
>
>  Public ReadOnly Property ListenImage() As Image
>
>        Get
>
>            If Me._listenImage <> String.Empty
Then
>
>                Try
>
>                    Return
Image.FromFile(Me._listenImage)
>
>                Catch ex As AccessViolationException
>
>                    Return Nothing
>
>                End Try
>
>            Else
>
>                Return Nothing
>
>            End If
>
>        End Get
>
>    End Property
>
>
>
>
>
> Stacey Levine
>
> Lead Technical Architect
>
> Value Music Concepts
>
> 825-C Franklin Court
>
> Marietta, GA 30067
>
> 678-229-4255
>
>
>
>
> ===================================
> This list is hosted by DevelopMentor(r)  http://www.develop.com
>
> View archives and manage your subscription(s) at
http://discuss.develop.com

>

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com


===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )