C#.NET: internal class accessible from another class using Type.GetType and Activator.CreateInstance?

I know that access modifier internal declared on a class makes it accessible from inside same assembly.

However, in my case another assembly is able to access internal class in another assembly using Type.GetType and is also able to create its object using Activator.CreateInstance() successfully.

I want to know is it really possible to be able to access an internal class in another assembly using Type.GetType() in another assembly? If not , then am i missing something?


Additional Details : I am going to specify a link containing class diagram of my Domain Driven Design (Model and Infrascture Layers) which use three assmbelies/projects:

Figure

For the sake of ease, i am going to explain bits about above class diagaram:

  1. Most external boundaries/rectangles are for assemblies/projects namely; A) sharemanagement.model, B) sharemanagement,
    C) sharemanagement.infrastructure.repositories

such that sharemanagement is like core (or library) which is referenced by sharemanagement.model and sharemanagement.infrastructure.repositories but sharemanagent assembly does not reference any of these two (because sharemanagement is the core/base library/assemblies on which other assemblies depend.

  1. rectangles inside rectangles are sub-directories.

Now, sharemanagement.model requests sharemanagement (using its repositoryFactory) to return an instance of CompanyRepository (defined in Sharemanagement.Infrastructure.Repositories) which sharemanagement obtains using Type.GetType and Activator.CreateInstance()

And, while creating instance of instance of CompanyRepository ( using Activator.CreateInstance() as mentioned above), the base class of CompanyRepository namely "SQLRepositoryBase" (defined in Sharemanagement ) gets an instance of EntityFactory (defined in Sharemanagement.Infrastructure.Repositories) using Type.GetType (from inside buildEntityFactory method of) EntityFactoryBuilder class.

Main point to note is that CompanyFactory is internal class and defined inside assembly "sharemanegement.infrastructure.repositories" whereas EntityFactoryBuilder.buildentityFactory() class is defined in assembly "sharemanagement".

Jon Skeet
people
quotationmark

However, in my case another assembly is able to access internal class in another assembly using Type.GetType and is also able to create its object using Activator.CreateInstance() successfully.

Indeed, assuming the code trying to do so has an appropriate trust level. Indeed, fully trusted code can do all kinds of things with reflection, including changing private fields. Code operating in a reduced trust environment can't do these things.

people

See more on this question at Stackoverflow