I have an assembly A that defines an interface with some overloads:
public interface ITransform
{
Point InverseTransform(Point point);
Rect InverseTransform(Rect value);
System.Drawing.Point InverseTransform(System.Drawing.Point point);
}
...and an assembly B that references A (the binary, not the project) and calls one of the overloads:
var transform =
(other.Source.TransformToDisplay != null &&
other.Source.TransformToDisplay.Valid) ?
other.Source.TransformToDisplay : null;
if (transform != null)
{
e.Location = transform.InverseTransform(e.Location);
}
To be precise, it calls the System.Windows.Point
overload of the InverseTransform
method, because that is the type of the property Location
in e
.
But when I build B in the IDE I get:
error CS0012: The type 'System.Drawing.Point' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
even though that's not even the overload I am calling. When I comment out the line where the overloaded method InverseTransform
is called, it builds fine even though I'm still instantiating an object of type ITransform
.
Why? And is there a way to fix this without having to add a reference to System.Drawing
everywhere?
The compiler needs to know what a System.Drawing.Point
is in order to prove that it's not the correct overload (eg, if it has an implicit conversion).
That method makes use of something defined in System.Drawing
. If you uncomment it then that assembly no longer will by trying to use System.Drawing
; hence, no requirement.
Think of it this way, when you go off to perform your action .NET says ok I'm making a call to this guy defined in this assembly and looks for the appropriate code to execute. It can't find it so it throws up it's hands and says I give up you tell me where it is.
Just make it a habit of referencing every DLL you might potentially use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With