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

Dynamic Assembly/Types With ReflectionPermissionFlag.RestrictedMemberAccess

My FlatFiles project uses System.Reflection.Emit to generate deserializers/serializers at runtime to read/write CVS files, etc. Until recently, I was able to simply use DynamicMethod passing in true for the restrictedSkipVisibility constructor…
3
votes
1 answer

Why has an InternalsVisibleTo referenced assembly also be signed?

I have a strongly named c# assembly: Strong.Named.Assembly.dll. It has the attribute InternalsVisibleTo with its public key, for another assembly: [assembly: InternalsVisibleTo("Another.Assembly, PublicKey=xxx")]. The Anoter.Assembly has not been…
scher
  • 1,813
  • 2
  • 18
  • 39
3
votes
1 answer

If private entities in F# compile to internal, why doesn't InternalsVisibleTo work?

From the F# 4.0 spec [PDF]: The CLI compiled form of all non-public entities is internal. In my main project I have a function defined as namespace MyNamespace.Foo module Bar = module Baz = let private myFun ... In the main project's…
cmeeren
  • 3,890
  • 2
  • 20
  • 50
3
votes
1 answer

Issue with InternalsVisibleTo attribute

I have two assemblies, say Main and Sub, where Sub depends on Main. Main defines a few classes that have protected internal virtual members, that I want to override in Sub. I override these members as protected override. There is an unrelated class…
GregRos
  • 8,667
  • 3
  • 37
  • 63
3
votes
1 answer

Can I use InternalsVisibleTo for C++ managed code?

I have C++ Managed project. And I'd like to test it with C# Nunit class library. I defined C++ class as internal ref class SomeClass{}; And how can I make it visible to C# class library?
dr11
  • 5,166
  • 11
  • 35
  • 77
3
votes
1 answer

Is there a way to make Code Analysis ignore "InternalsVisibleTo"?

We have a lot of assemblies that contain internal classes which we are unit-testing by using InternalsVisibleTo to make the internal classes visible to the Unit Test assembly. This works fine, but the problem is that as soon as you use…
Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
2
votes
1 answer

C# - Security concerns with InternalsVisibleTo attribute

Are there any security concerns with using the InternalsVisibleTo attribute with strong-named assemblies? I understand that the assembly receiving information this way must have the private key to decrypt the messages, and that within the…
Bohn507
  • 21
  • 1
  • 4
2
votes
2 answers

XmlSerializer and InternalsVisibleTo attribute

Is it possible to make XmlSerializer serialize internal class members by using InternalsVisibleTo attribute? If it is, what assembly should I make my internals visible to. In other words, what assembly name and public key should I provide to the…
e11s
  • 4,123
  • 3
  • 29
  • 28
2
votes
1 answer

InternalsVisibleTo is not working for wpf application

I have the [assembly:InternalsVisibleTo("GuiAssembly")] set in the other assembly but when wpf binding occurs on a class that lives in the other assembly, it throws an exception because of the property in that class being internal. I know this works…
Csharpfunbag
  • 395
  • 3
  • 19
2
votes
1 answer

Trusted pfx cert not working with InternalsVisibleTo attribute

I got a trusted cert from Comodo CA and having a hard time getting it to work with the InternalsVisibleTo Attribute. I'm getting a warning that the assembly is invalid and can't be resolved. I retrieved the public Key with…
JayTee
  • 1,114
  • 2
  • 11
  • 18
2
votes
0 answers

Do InternalVisibleTo and the Dynamic Language Runtime not work well together?

I have the following class in a Universal Windows exe project (actual functionality not included). sealed class DataPage { public DataPage(dynamic page) { Data = page; } public dynamic Data { get; private set; } } This…
dkackman
  • 15,179
  • 13
  • 69
  • 123
2
votes
1 answer

Silverlight security: giving a permission to access anonymous classes to a class library

I'm porting an existing class library to Silverlight. I used lambda expression compilation a lot and now I'm experiencing security problems because of it. In particular, if an anonymous class from a client SL app is participating in a lambda…
2
votes
1 answer

Is InternalsVisibleTo available to allow MonoTouch Unit Tests access to the internal of a MT Lib?

Can you use the InternalsVisibleTo assembly attribute in a AssemblyInfo file of a MonoTouch Library to allow MonoTouch Unit Test (Touch.Unit) access to the internals of the MonoTouch library? This is something that is great to use in non-MonoTouch…
Rodney S. Foley
  • 10,190
  • 12
  • 48
  • 66
2
votes
0 answers

Entity Framework: Mapping internal property from generic base type

I've got rather complicated real-life scenario of EF Mapping, which seems to work only if I break incapsulation. Maybe someone would clear it out how to do it correctly, or we'll accept it is a bug. I have 2 projects, let's call them Domain and…
2
votes
1 answer

Obfuscation when InternalsVisibleTo attribute is used?

I want to use the InternalsVisibleTo attribute solely to allow meaningful unit tests. However, I am worried that when I will build for release the internal members will not get obfuscated, even though no friend assemblies will be part of the release…
Stefan de Kok
  • 2,018
  • 2
  • 15
  • 19