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
1
vote
1 answer

Getting FileNotFoundException when loading assembly in C#

In C#, I have an assembly (AssemblyA) whose internals are visible to another assembly (AssemblyB) in the same solution, which I have achieved using [assembly: InternalsVisibleTo(AssemblyB, PublicKey=1234566.......)] However, AssemblyA is packaged…
codewario
  • 19,553
  • 20
  • 90
  • 159
0
votes
2 answers

Does a [TestMethod] have to be public? What consequences are there if it isn't?

I am using the test facilities provided by Microsoft.VisualStudio.TestPlatform.TestFramework. I have a test method decorated with [TestMethod]. I want to implement this test for various combinations of parameters using [DataRow]. One of the…
Hammerite
  • 21,755
  • 6
  • 70
  • 91
0
votes
0 answers

How to use testing with EntityFramework and Moq or Castle whereas Nuget EF packages does not have InternalsVisibleTo?

For my own projects i need to expose EF functionality with overriding some internal classes. It is a way to create Proxy classes with Emit or Moq or Castle and works with them, but it works only with EF compiled from GitHub sources. This sources…
Sellec
  • 64
  • 4
0
votes
3 answers

WPF two-way binding with internal setter

I'm using WPF's two-way binding on a CLR property, which implements INotifyPropertyChanged. The set for the property is internal, while the get is public. Unfortunately, I get the following error: System.Windows.Markup.XamlParseException was…
Omaer
  • 817
  • 1
  • 7
  • 22
0
votes
0 answers

Is it possible to use anonymous types and InternalsVisibleTo?

I am building a Xamarin.Forms application. I have two libraries: MyProj.ViewModels MyProj.DataAccess My DataAccess libary is accessing my Sqlite database and returning a dynamic object like so: var calls = from customer in…
JKennedy
  • 18,150
  • 17
  • 114
  • 198
0
votes
1 answer

What is the best practice when exposing classes from a library consisting of several assemblies?

I am in the process of creating a library which should be consumed by different applications. Those applications should not see the implementation details of the library but just be presented with a well usable interface. To get a clear project…
Chris
  • 6,914
  • 5
  • 54
  • 80
0
votes
1 answer

CodeContracts static checking says the members of an internal class of another assembly are not visible enough, despite using InternalVisibleTo

I'm writing a program in Visual Studio 2012, and I have a pair of classes in two separate projects: ProjectA: namespace Test { internal class A { private A(B b) { Contract.Requires(b.X != null); } } } ProjectB: namespace…
Philip C
  • 1,819
  • 28
  • 50
0
votes
0 answers

InternalsVisibleTo and class inheritance

I'm using InternalsVisibleTo attribute to make some internal classes visible to the unit test suite. While it's allowing me to create instances of internal classes, I cannot create a class that inherits from an internal class. Is this behaviour…
Doug
  • 6,322
  • 3
  • 29
  • 48
0
votes
1 answer

InternalsVisibleTo , different member variables to different assemblies

I have a class A_class in Project A. In class A_class, there is a constructor internal A_class() { //constructor logic } , and a member variable internal int A_member; Now there are two friend assemblies, say Assembly B and Assembly C I…
0
votes
2 answers

Implementing an internal interface over .NET Remoting

I had an internal interface that I needed to implement over .NET remoting to make sure only our assemblies ever called these members remotely (used InternalsVisibleTo to give access to friend assemblies). However, when I implemented the interface…
codewario
  • 19,553
  • 20
  • 90
  • 159
0
votes
1 answer

How I can modify InternalsVisibleTo in assembly using Reflexii?

I would to modify InternalsVisibleTo attribute value in assembly? In Reflector I see [assembly: InternalsVisibleTo(AssemblyName)] but I don't see AssemblyInfo.cs which I can modify. If it possible I'd like to change AssemblyName in the attribute to…
R.Titov
  • 3,115
  • 31
  • 35
1 2 3 4
5