0

when i call a function that comes from an other assembly and its accessibility level is 'internal', the intellisense should figure out a syntax error, such as "XXX is inaccessible due to its protection level". but it doesn't. without doubt, compilation failed.

however, after i change the function's accessibility level to an other level, such as 'private', it figures out the syntax error.

what makes 'internal' so different, and why? or it just a bug in visual studio?

sample code:

static void Main(string[] args)
{
    var t= new AssemblyBCode();
    t.test();
}

code in the other assembly (referenced solution):

public class AssemblyBCode
{
    internal void test() { }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
zhyy2008z
  • 37
  • 5

1 Answers1

1

Of course, internals idea is to hide the things from other assemblies while providing access to things fro 'original' assembly, but there's an assembly attribute called InternalsVisibleToAttribute with use of which you can explicitely instruct the framework that AssemblyA shall have access to internals of AssemblyB.

Of course*) for the IDE/compiler it should be perfectly clear*) if your current assembly has or has not access. It may be some petty bug or some problem with signing keys.. it's hard to say without seeing it by myself, unfortunatelly I dont have vs2012..

EDIT: *) see HansPassant comment: the problems is that it's NOT clear until after the assembly is signed at the end of the build job, which, probably, has not been properly finished yet.

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
  • thisis not an answer to the question. OP is asking my intellisense is (in his view) behaving incorrectly OP is not asking how to make internals visible to other assemblies – Rune FS Nov 08 '13 at 11:01
  • 1
    [InternalsVisibleTo] is in fact the problem. The IntelliSense parser cannot reliably determine whether that attribute is going to suppress the error. That requires signing the assembly, that happens later. – Hans Passant Nov 08 '13 at 11:20
  • Thank you Hans, that was just what I had in mind when speaking about 'problems with signing keys', but I didnt elaborate it enough. – quetzalcoatl Nov 08 '13 at 11:22