Why do I (sometimes) have to reference assemblies referenced by the assembly I reference?

后端 未结 5 1135
名媛妹妹
名媛妹妹 2020-12-06 10:53

I have an assembly A that defines an interface with some overloads:

public interface ITransform
{
    Point InverseTransform(Point point);
    Rect InverseTr         


        
5条回答
  •  囚心锁ツ
    2020-12-06 11:30

    The only difference between overloads are the types. That is why the compiler cannot distinguish which overload you're using without looking at the type.

    Since the type is not referenced by the executing assembly, the compiler doesn't know the type and needs a direct reference to the assembly containing the type definition.

    I ran in this issue myself and didn't want to add a direct reference to the assembly containing the type. I simply added an argument (boolean) to one of the methods so they are no longer overloads of eachother. The compiler then understood the difference between the methods, even if they have the same name, because they have a different amount of arguments. It no longer needed a reference to the assembly containing the type. I know it's not an ideal solution, but I couldn't find another solution as my method was a constructor so I couldn't change its signature in any other way.

提交回复
热议问题