Questions tagged [internalsvisibleto]

An attribute in .NET to expose members marked as internal to selected assemblies.

In .NET, members with the access modifier 'internal' are only visible to classes inside the current assembly. This can be circumvented by adding the InternalsVisibleTo attribute to the AssemblyInfo file.

This way, the assembly with the internal members can control which other assemblies have access to these members.

Both assemblies must be unsigned or both must be signed. If both are signed, the full public key must be included in the constructor of the attribute.

An unsigned assembly can expose the internal members to another unsigned assembly with (C# and VB.NET):

[assembly:InternalsVisibleTo("AnUnsignedAssembly")]
<Assembly:InternalsVisibleTo("AnUnsignedAssembly")>

For a signed assembly to expose the internal members to another signed assembly, the following can be used (C# and VB.NET):

[assembly: InternalsVisibleTo("SignedAssembly, PublicKey=002400000480000094" + 
                          "0000000602000000240000525341310004000" +
                          "001000100bf8c25fcd44838d87e245ab35bf7" +
                          "3ba2615707feea295709559b3de903fb95a93" +
                          "3d2729967c3184a97d7b84c7547cd87e435b5" +
                          "6bdf8621bcb62b59c00c88bd83aa62c4fcdd4" +
                          "712da72eec2533dc00f8529c3a0bbb4103282" +
                          "f0d894d5f34e9f0103c473dce9f4b457a5dee" +
                          "fd8f920d8681ed6dfcb0a81e96bd9b176525a" +
                          "26e0b3")]
<Assembly:InternalsVisibleTo("SignedAssembly, PublicKey=002400000480000094" + _
                         "0000000602000000240000525341310004000" + _
                         "001000100bf8c25fcd44838d87e245ab35bf7" + _
                         "3ba2615707feea295709559b3de903fb95a93" + _
                         "3d2729967c3184a97d7b84c7547cd87e435b5" + _
                         "6bdf8621bcb62b59c00c88bd83aa62c4fcdd4" + _
                         "712da72eec2533dc00f8529c3a0bbb4103282" + _
                         "f0d894d5f34e9f0103c473dce9f4b457a5dee" + _
                         "fd8f920d8681ed6dfcb0a81e96bd9b176525a" + _
                         "26e0b3")>
71 questions
7
votes
2 answers

InternalsVisibleTo attribute isn't working

Before I go on I did go through this InternalsVisibleTo attribute ain’t workin'! Hence the title Okay so I had a working version of my project that was using something like the following. [assembly: InternalsVisibleTo("Stuff.Test.Support,…
Terrance
  • 11,764
  • 4
  • 54
  • 80
6
votes
2 answers

Getting InternalsVisibleTo to work when the build process signs the assembly with strong names?

In our shop, we are using Cruise Control & MSBuild to automate the builds of the product as part of continuous integration. Part of the build is to sign the assemblies so they have strong names. In our project files when we develop locally, it does…
6
votes
1 answer

Which `[InternalsVisibleTo]` for .NET Framework and .NET Standard / Core framework assemblies?

I'm having an issue with cross-assembly / friend assembly type visibility. I have the following program (which I sign / strong-name). It tells Castle DynamicProxy (I'm using version 4.2.1 of the Castle.Core NuGet package) to create a proxy for my…
6
votes
3 answers

Releasing class library source, without signing key file, but unit-tests requires access to internal classes, what to do?

The situation is as follows: I want to release the full source to a class library I want to release binaries as well, signed by me, with a key file I don't want to publish I will provide batch files, and pre-build stepts, that creates a new key…
Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
5
votes
2 answers

How to define multiple friend assemblies when generating AssemblyInfo from .csproj file?

I would like to define several friend assemblies. It is easy to do so when editing the AssemblyInfo file manually: [assembly:InternalsVisibleTo("Friend1a")] [assembly:InternalsVisibleTo("Friend1b")] or [assembly:InternalsVisibleTo("Friend2a"), …
C. Meyer
  • 51
  • 3
5
votes
1 answer

InternalsVisibleTo except for a few classes

I applied InternalsVisibleTo to one of my projects in order for its internals to be visible for test projects. However, (this is weird I know) I need to mark a few internal classes so that they won't be visible to the projects which is indicated…
tugberk
  • 57,477
  • 67
  • 243
  • 335
5
votes
2 answers

Internal access for entities in Entity Framework makes simple linq where query crash

I am developing a library which use EF for database access. To avoid expose the entities outside the library, I have set the access of all tables to internal (I have also set to internal the Entity Container Access). The problem is that now, inside…
4
votes
2 answers

moq internal interface in Silverlight 4. "Can not create proxy for types that are not accessible."

I try to mock an internal interface in Silverlight 4, using moq-silverlight 4.0.10827.0. I get an error "Can not create proxy for types that are not accessible." in a Castle.DynamicProxy.Generators.GeneratorException. I have [assembly:…
jenspo
  • 504
  • 4
  • 11
4
votes
1 answer

InternalsVisibleTo for dynamically generated assembly, but with strong naming

I have a project that uses dynamic code generation to create a proxy class. This proxy class makes use of internal classes of the project (so that implementation details are not exposed) and so I use InternalsVisibleTo with the name of my…
Dan Bryant
  • 27,329
  • 4
  • 56
  • 102
4
votes
2 answers

Are There Any Non-UnitTesting Scenarios Where InternalsVisibleTo is Acceptable

It seems like using this attribute for anything other than unit testing of non-public methods/properties would be a huge code smell. Are there any legitimate uses of the InternalsVisibleTo attribute to achieve something that might be otherwise…
Joel B
  • 12,082
  • 10
  • 61
  • 69
4
votes
3 answers

What is "AllInternalsVisible" parameter of assembly:InternalsVisibleTo attribute?

My IntelliSense is coming up with a boolean named parameter "AllInternalsVisible=" in an [assembly:InternalsVisibleTo("AssemblyName")] declaration. Just position the cursor after the second double-quote and hit Ctrl-space. What is that - I cannot…
Greg Graham
  • 473
  • 7
  • 18
4
votes
1 answer

InternalsVisibleTo causes CS0246 error: The Type or Namespace could not be found

I am trying to enable one assembly to access another assembly's internal classes by adding [assembly:InternalsVisibleTo("assembly-name")] to the second assembly. However, this causes the following error: error CS0246: The type or namespace name…
Tim
  • 1,621
  • 4
  • 19
  • 35
4
votes
1 answer

InternalsVisibleTo, Signing and Unit tests, how to make it practical?

In "C# in Depth 2nd Edition", Jon Skeet's book - which I've just read until end of part 2 -, it is mentioned in 7.7.3 that InternalsVisibleTo can also be used with signed assemblies. At the moment I did not use signatures at all. The security issue…
jdehaan
  • 19,700
  • 6
  • 57
  • 97
4
votes
2 answers

Mocking internal classes with RhinoMocks

So I have a bunch of internal classes which I am trying to mock with RhinoMocks. I have added the following line to assemblyinfo.cs: [assembly:InternalsVisibleTo(RhinoMocks.StrongName)] However, this still does not allow me to mock internal…
jpoh
  • 4,536
  • 4
  • 35
  • 60
3
votes
1 answer

InternalsVisibleTo doesn't work with all assemblies. Some works, some not works

I have a Common DLL which have some internal methods for internal usage. Beside I also have 3 other projects WebServices, UnitTests and PATs In AssemblyInfo.cs of Common project, I added these lines: [assembly: InternalsVisibleTo("WebServices,…
Vi Tran
  • 31
  • 1
  • 4