I have two assemblies, say Main and Sub, where Sub depends on Main. Main defines a few classes that have protected internal virtual
members, that I want to override in Sub. I override these members as protected override
.
There is an unrelated class in Main, call it Main.Shared, that I want to use in Sub, but I don't want any other assemblies to see it. Here is how the situation looks:
//In assembly Main:
public class Shared
{
}
public class Parent
{
protected internal virtual void DoStuff()
{
}
}
//In assembly Sub:
public class Child : Parent
{
protected override void DoStuff()
{
base.DoStuff();
}
}
So I used the InternalsVisibleTo
attribute as usual. However, after I decorate Main with this attribute, the code refuses to compile. The error message says that I must now override DoStuff
as protected internal override
, presumably because it now thinks Main and Sub are the same assembly (?)
This is a big problem, since it means that I need to manually change every single override to protected internal, and there are many of them. Moreover, I might want to remove the attribute later, and then I would need to change everything back again.
Is there any way I can avoid doing this? (Besides a complete redesign of the code base...)
I'm also curious about why this happens at all. Is this behavior just some sort of blind spot, or is it supposed to work like this?