Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 类型。程序集给出了错误的程序集?_C#_Reflection_Com_.net Assembly - Fatal编程技术网

C# 类型。程序集给出了错误的程序集?

C# 类型。程序集给出了错误的程序集?,c#,reflection,com,.net-assembly,C#,Reflection,Com,.net Assembly,我想创建对Excel程序集的引用并使用以下代码: [Test] public void ExcelTest() { Assembly current = this.GetType().Assembly; Assembly excel = typeof(Microsoft.Office.Interop.Excel.Workbook).Assembly; Assert.AreEqual(current.FullName, excel.FullName); // Why is

我想创建对Excel程序集的引用并使用以下代码:

[Test]
public void ExcelTest()
{
    Assembly current = this.GetType().Assembly;
    Assembly excel = typeof(Microsoft.Office.Interop.Excel.Workbook).Assembly;
    Assert.AreEqual(current.FullName, excel.FullName); // Why is excel the same as current assembly?
}

[Test]
public void MscorlibTest()
{
    Assembly mscorlib = typeof(string).Assembly;
    Assert.IsTrue(mscorlib.FullName.StartsWith("mscorlib"));

    Assembly current = this.GetType().Assembly;
    Assert.AreNotEqual(mscorlib.FullName,current.FullName); // As expected
}
为什么excel与我当前的程序集相同

获取Excel程序集的好方法是什么


在阅读时找不到我的dumb。Excel是通过COM互操作类型访问的。它是一个界面,用GUID和其他东西装饰。使用它时,它使用COM与正在运行的Excel应用程序进行通信。因此,您的引用不是Excel本身,而是一个很薄的COM通信层

COM互操作类型可能嵌入到程序集中,这里似乎就是这样。可以将其指定为项目中程序集引用的属性


请参见示例:或

+1,这是有意义的,问题是在这样的情况下,如何获取Excel程序集?@Johan Larsson,据我所知,没有Excel程序集。Excel是本机应用程序,程序集是.NET库。这就是为什么你必须使用COM互操作来使用.NET。@ Drk程序集。LoadFile(PATH)给出了Excel程序集,但感觉很紧张。我认为Excel是用C++编写的。COM是一个独立于平台的通信层。COM在.NET中很重要,因为它可以用来与非.NET软件进行通信。Excel.exe运行时,它充当COM服务器,而您的应用程序是COM客户端。向COM接口添加引用时,将使用供应商提供的互操作程序集,或者从类型库生成新的互操作程序集。此COM接口层位于.NET程序集中。但它只是一个通信层,如果没有原生Excel本身,它是无用的。