Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging assemblies and using internal keyword

Does merging assemblies change the scope of the internal keyword?

I'm fairly certain that it wouldn't have an effect (or at least one that would matter) since anyone referencing the final assembly wouldn't be able to access internal classes anyway.

This might be a hypothetical question with no real world value, but I was curious nontheless.

Edit: I do mean with ILMerge, not combining source code into a single buildable assembly.

like image 334
Dustin Davis Avatar asked May 25 '11 18:05

Dustin Davis


2 Answers

Yes once the assemblies are merged, they get access to each others internal classes. This is specifically leveraged by some obfuscators to make public calls between assemblies into internal calls and then obfuscate them making it more secure. Reference: SmartAssembly

On a side note, using ILMerge, you can use the /internalize command line switch which will make all public classes in assemblies other than the primary assembly internal, which removes public interfaces from the end-user's eye but still the assemblies function normally.

like image 87
Teoman Soygul Avatar answered Oct 14 '22 12:10

Teoman Soygul


Assuming you are not running with full-trust , any types that were merged into the final assembly with the internal types would now be able to access the public members of the internal types.

So given assembly A:

public class MyClassA { ... }

and assembly B:

internal class MyClassB { ... }

MyClassA may not have permission to reflect the public members of MyClassB. If they were merged into the same assembly, then MyClassA may gain such a permission.

like image 3
CodeNaked Avatar answered Oct 14 '22 14:10

CodeNaked