-1

I have a solution consisting of about 10 important DLL files which are developed inside the same solution, when I release this solution, all the DLL files (public classes and functions inside) are open and usable to all others. How can I make the classes and functions inside a dll file visible and usable only by the same solution?!

Regards.

Moh
  • 1,887
  • 3
  • 18
  • 29
  • What have you tried? Take a look at obfuscation, you won't get much further than that. The DLL's can always be decompiled. – CodeCaster Jul 03 '12 at 13:24

2 Answers2

1

From your question, I understand that you know beforehand (i.e. at compile-time) what assemblies will be shipped together.

Therefore, there are two solutions:

  • Either, you mark your types as internal and deploy all of your code in one assembly. As you appear to be shipping all of the assemblies together, there's not really an inevitable reason to not combine everything in one assembly before shipping (except for licensing issues).
    If you can do that, you can still develop everything as separate projects and use some build tool to create an umbrella project file that includes all of your code.

  • Or, you make your types internal and declare the other assemblies in your solution as friends.
    Declare the InternalsVisibleToAttribute on an assembly whose internal types should be visible to another assembly in your solution.

Note that I've interpreted "visible" in the sense of "visible" to the compiler, so someone referencing your assembly can code against your APIs. If you want to prevent your code from really being visible in any fashion, you'll have to use obfuscation as suggested in CodeCaster's comment, and even that is probably not unbreakable.

Community
  • 1
  • 1
O. R. Mapper
  • 20,083
  • 9
  • 69
  • 114
  • By which way I can have all my assemblies (dll files) seperated after compilation and not usable by others? – Moh Jul 04 '12 at 11:50
  • @MOLi: I think I just answered that above (2nd list item). Please let me know what specific points are not clear. – O. R. Mapper Jul 04 '12 at 12:11
  • Sorry I was a bit busy, I'll test what you mentioned above and let you know about the result. Thanks in advance. – Moh Jul 06 '12 at 09:45
0

You could strong-name all your assemblies. Then, when a public method is called or a class is instantiated, you could get the calling assembly via Assembly.GetCallingAssembly() and check the strong name, then throw an exception if it doesn't match (not sure about performance of all that stuff though). That's all i can think of at the moment, other than putting everything into one assembly and making it internal.

Botz3000
  • 39,020
  • 8
  • 103
  • 127