AB4D Forum

Full Version: ReaderWmf leaks temporary files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the following code:

using (ReaderWmf reader = new ReaderWmf())
    Image image = reader.ReadGeometry(metaFile, geometrySettings);
    // ...

Every time this section is executed, a EMF file is created in %LOCALAPPDATA%.
There is a first chance exception on the closing brace (i.e. the Dispose call) "The process cannot access the file 'C:\Users\kg\AppData\Local\9333da9f-ef9d-4fd1-ab8a-66d8b0647bc0.emf' because it is being used by another process." Here is the call stack:
    mscorlib.dll!System.IO.__Error.WinIOError(int errorCode = 0x80070020, string maybeFullPath = "C:\\Users\\kg\\AppData\\Local\\9333da9f-ef9d-4fd1-ab8a-66d8b0647bc0.emf") + 0x321 Bytes    
    mscorlib.dll!System.IO.File.Delete(string path) + 0x99 Bytes    
    Ab2d.ReaderWmf.dll!Ab2d.ReaderWmf.ر() + 0x6c Bytes    
    Ab2d.ReaderWmf.dll!Ab2d.ReaderWmf.Dispose(bool disposing = true) + 0x2b Bytes    
    Ab2d.ReaderWmf.dll!Ab2d.ReaderWmf.Dispose() + 0x22 Bytes

Using Sysinternals ProcessExplorer I found that there is no other process having an open handle to the file (only my program itself).


Edit: Maybe this is the same problem as in the post "Problem with ReaderWmf Class in Web Service (WCF)". The metaFile variable in my code snippet is indeed a Stream.
It is indeed the same problem.
As a workaround, I saved the stream to a temporary file, called the ReadGeometry overload taking a file name and then deleted the temporary file again.
As you have correctly sad, the current version of ReaderWmf creates a temporary file when metafile is read from a stream.

I am preparing a release of a new version of ReaderWmf. I have already implemented reading metafiles directly from memory stream (without temp file). At first I was not aware that this is possible without a temp file, but after some additional investigation I have found a way to do it.

I think that the new version will be available in the next week.

Until than you can use the mentioned workaround.
I would like to inform you that the new version of ReaderWmf was just released - it does not create a temporary file any more when reading metafile from stream.

It also fixes some other problems.

For more information see the related blog post: