简体   繁体   English

使用C#代码生成问题-CS0012-IsLongModifier

[英]Build issue with c# code - CS0012 - IsLongModifier

I have a very simple piece of code which on compilation gives me the below error 我有一段非常简单的代码,在编译时会出现以下错误

Error CS0012 The type 'IsLongModifier' is defined in an assembly that is not referenced. 错误CS0012在未引用的程序集中定义了类型“ IsLongModifier”。 You must add a reference to assembly 'Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 您必须添加对程序集'Microsoft.VisualC,Version = 10.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'的引用。

Below is the relevant portion of the code 以下是代码的相关部分

grid.get_NumericalCell(rowIndex, "Bench2");

I get a red squiggly over the get_NumericalCell function call. 我在get_NumericalCell函数调用上模糊不清。

The method is available from a third party library which is implemented in C++/C#. 该方法可从以C ++ / C#实现的第三方库中获得。 Below is the signature of the method 下面是该方法的签名

double get_NumericalCell(int rowIndex, string columnName);

If I add a reference to Microsoft.VisualC, then the error disappears. 如果添加对Microsoft.VisualC的引用,则错误消失。

The reference documentation on IsLongModifier class was not much helpful in explaining why I am facing this issue. IsLongModifier类的参考文档在解释为什么我面临此问题方面没有太大帮助。

Can someone explain why I need a reference to Microsoft.VisualC.IsLongModifier - I don't see where I am referring to it in my code. 有人可以解释为什么我需要引用Microsoft.VisualC.IsLongModifier-我在代码中看不到在哪里引用它。

It's likely that the third-party library has a reference to Microsoft.VisualC . 第三方库可能引用了Microsoft.VisualC

The signature for get_NumericalCell() might have had an override in C++ that looked like this: get_NumericalCell()的签名在C ++中可能有一个重写,如下所示:

__gc class Grid 
{
   double get_NumericalCell(int i, string columnName) {}
   double get_NumericalCell(long l, string columnName) {}
};

That would be compiled to IL that looked like this: 它将被编译为如下所示的IL:

[...] float64 get_NumericalCell(int32 i, ...) [...]
[...] float64 get_NumericalCell(int32 modopt([Microsoft.VisualC]Microsoft.VisualC.IsLongModifier) l, ...) [...]

The optional modifier, IsLongModifier , is added to differentiate the two signatures, which would otherwise be identical. 添加了可选的修饰符IsLongModifier来区分两个签名,否则它们是相同的。 This hides the method in C# but the compiler might still need a reference to Microsoft.VisualC . 这将方法隐藏在C#中,但编译器可能仍需要引用Microsoft.VisualC You can check with reflection via the GetOptionalCustomModifiers() method. 您可以通过GetOptionalCustomModifiers()方法进行反射检查。

If you examine the third party assembly with a decompiler (ILDasm, ILSpy, .NET Reflector, dotPeek etc.), you'll see that the parameters of the method you're calling are decorated, at the IL level, with modifiers ( modopt ) of the type the compiler's complaining about (you can also write code to inspect them yourself: modopt and .NET reflection ). 如果您使用反编译器(ILDasm,ILSpy,.NET Reflector,dotPeek等)检查第三方程序集,您会发现所调用方法的参数在IL级别使用修饰符( modopt )(编译器抱怨的类型)(您也可以编写代码亲自检查它们: modopt和.NET Reflection )。 The compiler needs the reference at compile time to reason about the code to emit, the same way it sometimes complains about the lack of reference to the assembly with a base type of a type you're directly using, even though your compiled assembly does not end up referencing the "extra" assembly itself. 编译器在编译时需要引用来推理要发出的代码,以相同的方式有时它会抱怨缺少对您直接使用的基本类型的程序集的引用,即使您的编译程序集没有最终引用了“额外”程序集本身。

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

相关问题 CS0012 C#类型“ HttpContext”在未引用的程序集中定义 - CS0012 C# The type 'HttpContext' is defined in an assembly that is not referenced 带有显式调用的 C# 构造函数歧义 - 错误 CS0012 - C# Constructors Ambiguity with explicit call - Error CS0012 MSBuild错误CS0012 - MSBuild Error CS0012 CS0012 System.enum在未针对.NET 4.5的构建服务器上引用的程序集中定义 - CS0012 System.enum is defined in an assembly not referenced on build server targeting .NET 4.5 错误CS0012:类型“DbConnection”在未引用的程序集中定义 - Error CS0012: The type 'DbConnection' is defined in an assembly that is not referenced 错误CS0012:类型'TaskAwaiter <>'在未引用的程序集中定义 - error CS0012: The type 'TaskAwaiter<>' is defined in an assembly that is not referenced CS0012 类型“EventLogEntryType”在未引用的程序集中定义 - CS0012 The type 'EventLogEntryType' is defined in an assembly that is not referenced .Net Core-CS0012&#39;对象&#39;在未引用的程序集中定义 - .Net Core - CS0012 'Object' is defined in an assembly that is not referenced CS0012 从哪里获得信息? - Where does CS0012 get its information from? 使用RazorTemplates库时发生错误:&#39;CS0012:类型&#39;System.Attribute&#39;在未引用的程序集中定义&#39; - Error when using RazorTemplates library: 'CS0012: The type 'System.Attribute' is defined in an assembly that is not referenced'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM