Follow us

Access Internal access modifier into different assembly

As we know internal access modifier only can be accessible within same assembly but in case you require to access it into different assembly/library then you need to specify that assembly dependency into "AssemblyInfo.cs" properties file.

 

Here is the example where I have

  1. Test1 class with internal Result method inside same namespace and same assembly(TestConsoleApp1)
  2. Test2 class with internal Result method inside different namespace but same assembly(TestConsoleApp1)
  3. Class1 public class with public Result method inside different assembly(Test4.ClassLibrary)
  4. Class2 public class with internal Result method inside different assembly(Test4.ClassLibrary)
  5. Class1 internal class with internal Result method inside different assembly(Test4.ClassLibrary)

As result of above ,

  • "1 & 2" I can access easily in same assembly(TestConsoleApp1) main function.
  • "3" which is in different assembly, still I can access because class and method both are public.
  • "4" which is in different assembly, only I can access the class but not method as class is public but method is internal.
  • "5" which is in different assembly, I cannot access class and method both as both are internal.

So to allow "4" and "5" both method accessible into assembly(TestConsoleApp1) we have to specify the assembly dependency into "AssemblyInfo.cs" properties file of same assembly i.e. (Test4.ClassLibrary) where these classes exists and specify where(in which assembly) this will be accessible).

 

Here is the code screenshots-

Assembly(TestConsoleApp1)

Assembly(Test4.ClassLibrary)

Assembly(Test4.ClassLibrary) - AssemblyInfo.cs file to specify dependency

Categories/Tags: Internal access modifier~Internal access specifier

Recent Articles

1

AWS Saving Plan - Cost optimization tips

2
3

AWS RDS Key Concepts & Why you should use it?

4
5

Open-Search/Kibana - Multi Tenancy Setup

See All Articles