简体   繁体   中英

intellisense can't figure out a 'internal' accessibility level syntax error of in visual studio & C#

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() { }
}

Of course, internal s 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 internal s 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM