Reputation: 4394
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. You must add a reference to assembly '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.
The method is available from a third party library which is implemented in 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.
The reference documentation on IsLongModifier class was not much helpful in explaining why I am facing this issue.
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.
Upvotes: 2
Views: 670
Reputation: 99957
It's likely that the third-party library has a reference to Microsoft.VisualC
.
The signature for get_NumericalCell()
might have had an override in C++ that looked like this:
__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:
[...] 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. This hides the method in C# but the compiler might still need a reference to Microsoft.VisualC
. You can check with reflection via the GetOptionalCustomModifiers()
method.
Upvotes: 3
Reputation: 5405
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). 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.
Upvotes: 2