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
2
votes
3 answers

How to have "public public" v/s "internal public"?

Possible Duplicate: When should [assembly: InternalsVisibleTo()] be used? Access to dll methods I have two assemblies, A.dll and B.dll. A.dll has some common features, and B.dll uses it. I have to distribute A.dll and B.dll for other users…
Anash P. Oommen
  • 607
  • 3
  • 10
2
votes
1 answer

SGEN, InternalsVisibleTo and assembly signing

I'm trying to do something a bit unusual... I have this class Foo : public class Foo { public Foo(string name) { this.Name = name; } internal Foo() { } public string Name { get; internal set; } public int…
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
2
votes
3 answers

Non-code-generated forwarding shim for testing private methods

In general, I design classes in such a manner as to not require access to privates for testing purposes. An InternalsVisibleTo can also assist. However, I'm currently dealing with a codebase that has a few area which have become reliant on the…
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
1
vote
1 answer

Alternative to InternalsVisibleTo

I am currently trying to write unit tests in my solution, but I want to put my unit tests in a different separate project. The problem is when I am generating some fake testing data I need to set properties of classes, but this is impossible because…
picaCHuXX
  • 91
  • 7
1
vote
1 answer

.NET's "InternalsVisibleTo" equivalent in Haskell

In .NET I can decorate my assembly with the following attribute: [] Thanks to this, all the modules marked as "internal" are accessible from "MyProject.Test". I can use it e.g. for unit testing the…
LA.27
  • 1,888
  • 19
  • 35
1
vote
0 answers

Dependency injection and InternalsVisibleTo attribute

In my solution I have an IoC container (Ninject) in its own module. It works fine to resolve dependencies between public classes of all modules, but how could it resolve dependencies of internal classes? I have a public class called Customer, in the…
1
vote
1 answer

Microsoft Fakes Internal Classes Shim not generated

I have Windows Form App(assembly named "WindowsFormsApplication1") and I have Unit Test project(assembly named "UnitTestProject2"). I added InternalsVisibleTo attribute into "WindowsFormsApplication1\AssemblyInfo.cs" like [assembly:…
1
vote
2 answers

referencing and storing the strong name externally for reuse

I have a lot of assemblies that have set the InternalsVisibleToAttribute pointing one specifc assembly within the same solution. Unfortunately the assembly that is being pointed to has a stong name, so I always have to put the same public key token…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
1
vote
1 answer

InternalsVisibleTo - not working in ascx/aspx file

I set the InternalsVisibleTo attribute for the friend assembly. In a controller, I can access the internal class, but if I try to do the same in the aspx/ascx file - "class is inaccessible due to its protection level" . Any way I could fix this…
sirrocco
  • 7,975
  • 4
  • 59
  • 81
1
vote
1 answer

Setting Assembly Info for InternalsVisibleTo with MSBuild Community Tasks

I'm using MSBuild Community Tasks to automatically update my assembly version numbers according to my Subversion repository tag. I have added the following to my project file: This gives me a new AssemblyInfo.cs file: unfortunately I need to add…
1
vote
2 answers

How to show a progress bar for a layout until the SmartImageView is loaded

How can I trigger spinner.setVisibility(View.GONE); after SmartImageView is loaded? protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity); mUrl =…
user3245604
  • 79
  • 1
  • 6
1
vote
1 answer

Sgen throws an error with internal setter in VS2012

Does SGen generate xml serialization assemblies only if all setters are public? I've got this class in DummyProject: public class DummyClass { public int Sequence { get; internal set; } } In my AssemblyInfo.cs, I've declared this: [assembly:…
1
vote
1 answer

Can't get the full public key for 4.0 beta 2 assemblies

I'm having an issue getting the public keys for some of the .net 4.0 beta 2 assemblies so I can make my internals visible to them (gross). Normally, I'd just pop into SN.EXE and poof I'd have them. But instead of getting what I'd normally expect I'm…
user1228
1
vote
1 answer

Wcf Friend Assemblies on iis, not working at runtime

i have a problem regarding InternalsVisibleTo. I have an Assembly named A with an internal test class I have a Wcf Service (WcfService1) hosted on iis that is referencing this assembly via static linking (add reference on visual studio). i have the…
Fzan
  • 75
  • 11
1
vote
1 answer

Unit testing with InternalsVisibleTo does not work for internal methods using dynamic parameters

I'm trying to use the InternalsVisibleTo to allow me to test a utility / helper method from a separate Test assembly. When I try and call an internal method with a dynamic parameter I get the error "RuntimeBinderException was unhandled ... is…