简体   繁体   中英

Difference between how Visual studio loads assemblies and Assembly.LoadFrom?

I have an assembly (2 actually) both are from SAP directory C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui .

  • Visual Studio Add Reference - Works just fine.
  • Assembly.LoadFrom - Throws exception below.

Could not load file or assembly 'file:///C:\\Program Files (x86)\\SAP\\FrontEnd\\SAPgui\\sapfewse.ocx' or one of its dependencies. The module was expected to contain an assembly manifest.

Why is it that I can add the reference to visual studio and use the dll that way no problem, but loading it via reflection doesn't work?

Is there a way to load the assemblies types at runtime?

As Lucas pointed out in the comments, Assembly.LoadFrom only works on .NET assemblies and the assemblies I was trying to load were COM dlls.

What I ended up having to do was add them to a project which produced Interop versions of the dlls which I then added to the GAC so that the program we originally wanted to use it with could access it.

Thank you to everyone who posted in the comments that lead me to this solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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