I'm writing a program in Visual Studio 2012, and I have a pair of classes in two separate projects:
ProjectA:
namespace Test
{
internal class A
{
private A(B b)
{
Contract.Requires(b.X != null);
}
}
}
ProjectB:
namespace Test
{
internal class B
{
public string X;
}
}
In AssemblyInfo.cs
in ProjectB, I also have:
[assembly: InternalsVisibleTo("ProjectA")]
This compiles just fine until I turn on CodeContract static analysis. At this point, I get an error from ccrewrite: Member 'Test.B.X' has less visibility than the enclosing method Test.A.#ctor(Test.B)
.
The only thing that I can think might be causing the problem is that CodeContracts doesn't know that ProjectA can see ProjectB's internals, and thus believes that class B
's visibility is essentially none with this context. Although if I change the assertion to b != null
, it seems to be fine, so maybe this argument doesn't hold water.
Can anyone confirm this assertion, or give me a correct explanation, and short of removing the Requires
, turning off CodeContracts or changing the visibility of B
, is there a way around this error?