New Bitmap causing exception

H

HW

Hi, I'm getting a SystemUnAuthorised exception with the following bit
of code, separated out for clarity

Dim memStr As MemoryStream

memStr = New MemoryStream(imageptr)

picBox.Image = New Bitmap(memStr) <- exception here



Strangely it doesn't get caught by the Try Catch block but only by the
debugger. In the call stack

window it seems to be in mscorlib.dll Sytem.IO.memoryStream.GetBuffer.
imageptr is obtaimed from reading a

an image file which i've checked is not readonly. So why is the BitMap
constructor call throwing this

exception.
 
H

HW

Please ignore last post, i still have this exception. Definitely something
up with Bitmap constructor call
 
H

HW

imageptr is Byte array, basically i have a byte array and i'm converting
to Bmp using New Bitmap call and am getting UnAuthorised Exception
 
G

Guest

It's a byte array of what type of actual data? Is the source a BMP, JPG,
GIF, etc?

-Chris
 
H

HW

Hi Chris, the source is a BMP. I've now found out that the

MemoryStream class has several overloads and involves a call to GetBuffer
which raises this exception if the buffer is not PUBLICLY VISIBLE

By using this version
Public Sub New ( _
buffer As Byte(), _
index As Integer, _
count As Integer, _
writable As Boolean, _
publiclyVisible As Boolean _
)and settig publiclyVisible to TRUEthe exception has now gone. This exception was killing my app performance wiseand is not caught using try,catch exception handling, i only spotted using debuggerby turning on exceptions, plus it doesn't seemto actually functionally make any difference using the wrong version of the Memorystream class overload. Why do Microsoft let this go through if you use the wrongversion, it just allows bugs to get through.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top