Rebex Security: because it is being used by another process

0 votes
asked Oct 18, 2017 by TopCoder (140 points)

Is there a fix or workaround for this? No other process is using it and it happens on occasion?

The process cannot access the file 'filename' because it is being used by another process. Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Rebex.IS.L(String B, FileMode R, FileAccess I, FileShare A, RS J) at Rebex.Security.FileEncryption.IE(String B, FileMode R, FileAccess I) at Rebex.Security.FileEncryption.RE(String B) at Rebex.Security.FileEncryption.L(String B, String R)

1 Answer

0 votes
answered Oct 18, 2017 by stepantalalayev (3,180 points)

Hello,

The thing is that .NET error messages sometimes happen to be a bit confusing. This exception could be raised by your own code when you use System.IO methods in your code. You can replicate the same error if you try to do something like that:

System.IO.File.Create(@"C:\temp\test.txt");
System.IO.File.Open(@"C:\temp\test.txt", FileMode.Open);

Maybe you created a file or opened a stream which were not closed later.

The solution in this case would be to call .Close() method (or some equivalent) at the end of working with file, like that.

System.IO.File.Create(@"C:\temp\test.txt").Close();

This method will release the file handle and allow you to open it again later.

...