简体   繁体   English

调用 Dispose 时未找到入口点

[英]Entry point was not found on calling Dispose

I'm unit testing a piece of code that uses a nested using statement.我正在对一段使用嵌套 using 语句的代码进行单元测试。 I've changed it to a using statement in a try/finally block.我已将其更改为try/finally块中的using语句。 When I try to call the Dispose method in the finally block I get an EntryPointNotFoundException .当我尝试在finally块中调用Dispose方法时,我得到一个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?我该如何解决这个问题?

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.程序集具有对在未来版本中实现 IDisposable 的对象的引用,但在运行时加载了旧版本。 So when it tried to call Dispose(), which didn't exist in the old version, it goes ummmmm EntryPointNotFoundException!因此,当它尝试调用旧版本中不存在的 Dispose() 时,它会发生 ummmmm EntryPointNotFoundException!

Long version:长版:

  • In version 1 of ThirdPartyComponent, Thing did not implement IDisposable.在 ThirdPartyComponent 的版本 1 中,Thing没有实现 IDisposable。
  • In version 2 of ThirdPartyComponent, Thing did implement IDisposable.在 ThirdPartyComponent 的第 2 版中,Thing确实实现了 IDisposable。
  • ProjectA was built referencing version 2 of ThirdPartyComponent. ProjectA 是参考 ThirdPartyComponent 的第 2 版构建的。 IDisposable is valid, and the "using" gets compiled just fine. IDisposable 是有效的,并且“使用”被编译得很好。
  • ProjectA loaded version 1 of ThirdPartyComponent, and tries to call "Dispose()". ProjectA 加载了 ThirdPartyComponent 的版本 1,并尝试调用“Dispose()”。 It freaks out because there is no "Dispose()" in version 1. Of course, it should have loaded version 2, but sometimes the world isn't fair (in my case, a custom assembly loader messed up).它吓坏了,因为版本 1 中没有“Dispose()”。当然,它应该加载版本 2,但有时世界并不公平(在我的情况下,自定义程序集加载器搞​​砸了)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM