- Home /
accessing a class by interface requries reference to other unrelated interface's assembly
Hey, been having some weirdness in my code, I think I get where the problem is but I wanted some clarification.
I have 2 separate classes and 2 interfaces in a few different assemblies.
FightingText, which is in the "fightlogic" assembly
Creature, which is in the "StatBased" Assembly
IreturnPronouns, an interface which is defined in the "TextLogic" Assembly
and ItakeDamage, an interface defined in "InteractionInterfaces" Assembly
to quickly explain how they are implemented:
public class Creature : IreturnPronouns, ItakeDamage
public class FightingText{
function1(Creature c, ItakeDamage victim)
function2(Creatrure c1, Creature c2)
}
fightlogic has a reference to StatBased and InteractionInterfaces
StatBased has a reference to both interfaces' Assembly.
When Programming a function that has the signature of function1 (no body yet) I noticed, that it was throwing the exception:
The type IreturnPronouns is defined in an assembly that is not referenced. You must add a reference to assembly
Granted, fightlogic does not reference TextLogic, so it doesn't know IreturnPronouns, but in this case I am not using IreturnPronouns, I only require ItakeDamage. And when I changed the signature to the one described above as function2 it does not throw the error anymore. This confuses me. Why is IreturnPronouns a problem here? As far as I understand TextLogic wants to use interfaces inside of Creature but cannot access IreturnPronouns, since they are not in the same assembly.
But in this case when using creature it doesn't throw the error unless I use the function provided by the interface and when using the interface that is completely unrelated to IreturnPronouns it throws the Error.
Can you guys help me understand this? Is this kinda remote access even good practice? My assembly definiton references are always one way only, never circular, so I thought I was clear on how to correctly use them, but the info I can find on them and understand is quite scarce, so I may be using them wrong.
Any advice?