Question


I have a method declared with internal static in one of my classes and i would like to expose this method to another class in a particular assembly can anybody help me with this please?

Was it helpful?

Solution

In your AssemblyInfo.cs file in the assembly that contains your internal method, use the following line:

[assembly: InternalsVisibleTo("OtherAssemblyName")]

If you receive the following error...

Friend assembly reference 'OtherAssemblyName' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

Then see the modification here: How to declare a friend assembly?

This, however, will give your other assembly visibility into all of your internals in your original assembly. You can't just expose one internal to a friend assembly.

OTHER TIPS

C# doesn't have friend types, it only has friend assemblies.
This means that you can't make a specific internal type visible to a specific type in another assembly.

All you can do is to make all internal types - and internal class members of - visible to all classes of another assembly via the InternalsVisibleTo attribute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top