There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Native Exception in AlphaImage Draw method
The problem is because a managed array is passed to the COM object. Once the garbage collector decides to free/move this array all hell break loose.
Here's a fix:
In IImagingFactory.cs, replace:
// We need the MarshalAs attribute here to keep COM interop from sending the buffer down as a Safe Array.
uint CreateImageFromBuffer([MarshalAs(UnmanagedType.LPArray)] byte buffer, uint size, BufferDisposalFlag disposalFlag, out IImage image);
uint CreateImageFromBuffer(IntPtr buffer, uint size, BufferDisposalFlag disposalFlag, out IImage image);
In AlphaImage.cs add this in the top of the file:
factory.CreateImageFromBuffer(pbBuf, cbBuf, BufferDisposalFlag.BufferDisposalFlagNone, out alphaImage._image);
// Copy stream data into an unmanaged global buffer that will be freed by the factory once image is decoded
// note that we cannot pass pbBuf directly since it might be moved around or freed by the gc.
IntPtr p = Marshal.AllocHGlobal((int)cbBuf);
Marshal.Copy(pbBuf, 0, p, (int)cbBuf);
factory.CreateImageFromBuffer(p, cbBuf, BufferDisposalFlag.BufferDisposalFlagGlobalFree, out alphaImage._image);