简体   繁体   中英

Interop assembly not found in F# solution

F# newbie here, spent many painful hours trying to resolve the errors with a simple piece of code from MSDN F# tutorial.

#r "Microsoft.Office.Interop.Excel.dll" 
// fails with invalid/not found errors

#r "Microsoft.Office.Interop.Excel" // works like a charm.

Any F# gurus know why?

"Microsoft.Office.Interop.Excel.dll" is the name of a file (inferred, because of the .dll suffix). When you supply a file name, #r will look for that file in the file system. Since you didn't supply a path, it'll look in your present working directory. Most likely, "Microsoft.Office.Interop.Excel.dll" isn't in your working directory. This explains why the first example fails.

"Microsoft.Office.Interop.Excel" , on the other hand, is inferred to be the name of an assembly (because there's no file extension). Assemblies are libraries, and are normally distributed in .dll files. They don't have to, though; they can, for example, be dynamically emitted at run-time. Additionally, a .dll file can technically contain more than a single assembly, although I've never seen this in the wild. The most normal case is that a .dll file contains a single assembly, and that the name of the file corresponds to the name of the assembly.

When you request to load an assembly, the .NET assembly loader (called Fusion ) starts looking for an assembly with the requested identity . It'll start looking in the Global Assembly Cache , and my guess is that it finds the "Microsoft.Office.Interop.Excel" assembly there. This explains why the second example succeeds.

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