.NET 非托管库加载:处理错误状态
我正在编写一个使用非托管库的程序。 处理可用 foo.dll 版本不兼容的情况的最佳实践是什么?
示例:用户启动程序并拥有比程序预期版本更旧的 DLL 版本。无论如何,您是否会尝试使用它,因为在成熟的库中破坏 API 更改应该不常见?立即报错?维护程序中的资源以及所使用的每个非托管 DLL 的下载位置? 或者最好将每个 DLL 包含在项目自己的文件夹中并坚持使用该文件?
目前,我执行后者,并使用新的项目版本更新 DLL,但我希望我的软件尽可能具有容错能力,并且我不知道使用非托管 DLL 的任何最佳实践(除了“除非必要,否则不要使用它们”)。
I am writing a program that uses an unmanaged library.
What is a best practice to handle a situation where the available foo.dll is of an incompatible version?
Examples: The user starts up the program and has an older version of the DLL than that which the program is expecting. Would you try to use it anyway, as breaking API changes should be uncommon in a mature library? Immediately error out? Maintain a resource in the program with download locations to every unmanaged DLL used?
Or is it considered best to include every DLL in the project's own folder and insist on using exactly that file?
For now, I do the latter, and update the DLL with new project versions, but I'd like my software to be as fault-tolerant as is practical and I am unaware of any best practices for the use of unmanaged DLLs (other than "don't use them unless you have to").
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设非托管 DLL 在编译时嵌入了版本信息,您可以在应用程序加载时使用 System.Diagnostics 中的 FileVersionInfo 类来检查兼容版本。
如果没有找到兼容版本然后提醒用户?
http://msdn.microsoft.com/en-us/library /system.diagnostics.fileversioninfo.aspx
Assuming the unmanaged DLL has version info embedded when compiled you could use the FileVersionInfo class in System.Diagnostics at application load to check for compatible versions.
If no compatible versions are found then alert the user?
http://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo.aspx