Is it possible to make internal classes from my assembly visible to other assemblies?
I know about the AssemblyInfo file and the [assembly: InternalsVisibleTo()]
attribute, but it doesn't work in my case.
The main purpose is to make it possible to call methods from LINQPAD, so this [assembly: InternalsVisibleTo("LINQPad")]
doesn't work. I don't know why. In my project, I'm using dependency resolver, and it is hard to do such a thing in LINQPAD. Any suggestions?
You can use the InternalsVisibleTo attribute and provide the name of a specific assembly that can see the internal types in your assembly.
Assembly-level attributes can appear in any code file; however, by convention they are placed in the AssemblyInfo file. This aids discoverability, as this is where people (or tools) will commonly look when investigating issues. I have been using InternalsVisibleTo for many years and placing it in the AssemblyInfo file.
What Does Internal Mean? Internal, in C#, is a keyword used to declare the accessibility of a type or type member such that the access is limited to the assembly in which it is declared. An internal modifier is used to prevent the use of a public modifier, which allows access to other assemblies wherever necessary.
I've just uploaded a new beta that allows this to work.
Add the following attribute to the libraries whose internals you want LINQPad to access:
[assembly: InternalsVisibleTo("LINQPadQuery")]
You'll also need to enable this feature in LINQPad's preferences (Edit | Preferences | Advanced).
Let me know how you get along.
You can also go to the project properties into AssemblyInfo.cs file and set it there.
For example:
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("*****)] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("*****")] [assembly: AssemblyProduct("*****")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: InternalsVisibleTo("[HERE IS YOUR ASSEMBLY WHERE YOU WANT TO SEE INTERNALS OF CURRENT ASSEMBLY")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("6fbd2c14-031d-48cc-9cc6-f1b85d701e89")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With