C# 获取非托管 dll 的版本
我正在从托管 c# 代码调用非托管 dll,并想检查我正在调用正确的版本。
我尝试加载程序集(然后获取资源文件,然后获取版本)的代码是: cur_version = Assembly.LoadFile("X:\Workspace\yreceipts_pos\yRprintProcessor\Debug\yRprintProcessor.dll"); 由于此错误而失败: 该模块应包含程序集清单。 (HRESULT 异常:0x80131018)
有谁知道如何解决此问题或有更好的方法从托管 C# 代码检查非托管 dll 的版本吗?
提前致谢, 理查德
I'm calling an unmanaged dll from my managed c# code and wanted to check I'm calling the right version.
The code I'm trying to load the assembly (to then get the resource file and then get the version) is:
cur_version = Assembly.LoadFile("X:\Workspace\yreceipts_pos\yRprintProcessor\Debug\yRprintProcessor.dll");
It's failing because of this error:The module was expected to contain an assembly manifest. (Exception from HRESULT: 0x80131018)
Does anyone know how to get around this or have a better way to check the version of an unmanaged dll from managed c# code?
Thanks in advance,
Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如logicnp所述; Assembly.Load 仅适用于托管程序集。要确定任何版本化文件的版本,您可以使用 System.Diagnostics.FileVersionInfo.GetVersionInfo(filename) 并加载和调用 DLL 中的非托管过程,您可以参考以下文章:
http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx
http://blogs.msdn.com/jonathanswift/archive/2006/10/03/Dynamically-calling-an-unmanagement-dll-from-.NET-_2800_C_23002900_.aspx
祝你好运...
As stated by logicnp; the Assembly.Load is for managed assemblies only. To determine the version of any version-ed file you can use System.Diagnostics.FileVersionInfo.GetVersionInfo(filename) and to load and call unmanaged procedures in DLLs you can refer to these articles:
http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx
http://blogs.msdn.com/jonathanswift/archive/2006/10/03/Dynamically-calling-an-unmanaged-dll-from-.NET-_2800_C_23002900_.aspx
Good luck...
失败的原因是您无法使用 Assembly.Load 加载非托管 dll。请参阅大卫·布朗建议的链接。
The reason it fails is becuase you cannot use Assembly.Load to load unmanaged dlls. See the link suggested by David Brown.