简体   繁体   English

在F#解决方案中找不到互操作程序集

[英]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. F#newbie在这里花了很多时间来尝试使用MSDN F#教程中的一段简单代码来解决错误。

#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? 任何F#大师都知道为什么?

"Microsoft.Office.Interop.Excel.dll" is the name of a file (inferred, because of the .dll suffix). "Microsoft.Office.Interop.Excel.dll"文件的名称(由于.dll后缀而推断)。 When you supply a file name, #r will look for that file in the file system. 提供文件名时,# #r将在文件系统中查找该文件。 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. 最有可能的是, "Microsoft.Office.Interop.Excel.dll"不在您的工作目录中。 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). 另一方面, "Microsoft.Office.Interop.Excel"被推断为程序集的名称(因为没有文件扩展名)。 Assemblies are libraries, and are normally distributed in .dll files. 程序集是库,通常分布在.dll文件中。 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. 另外, .dll文件在技术上可以包含多个程序集,尽管我从未在野外看到过这种情况。 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. 最常见的情况是.dll文件包含单个程序集,并且文件名对应于程序集的名称。

When you request to load an assembly, the .NET assembly loader (called Fusion ) starts looking for an assembly with the requested identity . 当您请求加载程序集时,.NET程序集加载程序(称为Fusion )开始查找具有所请求标识的程序集 It'll start looking in the Global Assembly Cache , and my guess is that it finds the "Microsoft.Office.Interop.Excel" assembly there. 它将开始查看全局程序集缓存 ,我的猜测是它在那里找到"Microsoft.Office.Interop.Excel"程序集。 This explains why the second example succeeds. 这解释了为什么第二个例子成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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