C# getting version of unmanaged dll

依然范特西╮ 提交于 2020-02-24 13:51:30

问题


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


回答1:


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...




回答2:


The reason it fails is becuase you cannot use Assembly.Load to load unmanaged dlls. See the link suggested by David Brown.



来源:https://stackoverflow.com/questions/2459786/c-sharp-getting-version-of-unmanaged-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!