Reputation: 246
I'm unit testing a piece of code that uses a nested using statement. I've changed it to a using
statement in a try/finally
block. When I try to call the Dispose
method in the finally
block I get an EntryPointNotFoundException
. I've tried a lot of things but I'm not sure how to solve this problem. Here is my code:
var memoryStream = new MemoryStream(message.FileContent);
try
{
using (var sftpClient = this.GetSftpClientFromId(message.CustomerId))
{
return sftpClient.UploadFileAsync(memoryStream, message.FileName, true);
}
}
finally
{
memoryStream?.Dispose();
}
How can I solve this issue?
Upvotes: 3
Views: 673
Reputation: 3252
Just had this happen.
The problem ended up being:
Short version:
An assembly had a reference to an object that implemented IDisposable in a future version, but an old version was loaded at runtime. So when it tried to call Dispose(), which didn't exist in the old version, it goes ummmmm EntryPointNotFoundException!
Long version:
Upvotes: 3