Quantcast
Channel: Microsoft Dynamics AX Forum - Recent Threads
Viewing all articles
Browse latest Browse all 175888

file access issue

$
0
0

Hello,

Deletion of the file is throwing error that can't access file or other process is using it.

Below are the steps i am doing.

1) I am generating PDF file from SSRS report and it gets placed in temp folder on the AOS server.

2) I am converting the file to MemoryStream

3) calling a method which processes the Memorystream.

4)  deleting the file from temp folder.

Below is the code  that starts from step 2 assuming step 1 is already performed.

-----------------------------------------------------------------------------

new FileIOPermission(tempFileNameWithPath, #io_read).assert();

if (WinAPIServer::fileExists(tempFileNameWithPath))
{

reportIsEmpty = (WinAPIServer::fileSize(tempFileNameWithPath) == 0);

// starts creating memorystream

fileStream = System.IO.File::OpenRead(tempFileNameWithPath);
memoryStream = new System.IO.MemoryStream();
size = fileStream.get_Length();
memoryStream.SetLength(size);
fileStream.Read(memoryStream.GetBuffer(), 0, size); //write to MemoryStream

// call the method to process memorystream
}

CodeAccessPermission::revertAssert();

// Some other business logic goes here which has nothing to do with file or memorystream created above.

new FileIOPermission(tempFileNameWithPath, #io_write).assert();
WinAPIServer::deleteFile(tempFileNameWithPath);
CodeAccessPermission::revertAssert();

I am getting error when i am trying to delete the file shown in green section above. If i comment out red color code, everything works fine and file gets deleted successfully. but somehow permission is not getting reverted eventhough i have used revertAssert() statement (Pink color) before deleting file.

 

I believe file is getting locked when memorystream is getting generated and never gets unlocked.

Can anyone help me how to get rid of this lock?

 

 


Viewing all articles
Browse latest Browse all 175888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>