locked
Safe to use InternalsVisibleToAttribute for seperate assemblies that need to share RRS feed

  • Question

  • I am writing an app that will end up being several assemblies.

    I am thinking that I want to use the attribute: InternalsVisibleToAttribute to allow the assemblies to talk to each other.

    It seems like it is safe from hacking because the signed assemblies use public/private keys for protection.

    Is this a good way to provide this kind of interaction, or is there a more recommended way to do it?

    Thanks in advance!

    Bob
    • Moved by Peter Ritchie Thursday, June 5, 2008 3:59 PM better forum
    Saturday, May 31, 2008 4:19 AM

Answers

  • Personally I only really use InternalsVisibleTo for unit tests; note that either way it doesn't really give you much safety - it isn't hard to bypass private/internal modifiers via reflection. And note that the IDE doesn't support circular references (if A references B, B can't reference A). If you need smoething close to circular, you'd be better off using a 3rd assembly to define some interfaces and use a "dependency injection" / "inversion of control" approach to expose the methods of each via interfaces.


    Marc
    • Marked as answer by jack 321 Wednesday, June 4, 2008 2:22 AM
    Saturday, May 31, 2008 8:23 AM
  • To answer your question, you can use [InternalsVisibleTo] across your application assemblies.  This has nothing to do with hacking, as Marc pointed out, because accessibility modifiers are not enforced by the runtime.

    The primary reason to avoid [InternalsVisibleTo] is that it encourages coupling between assemblies, that are otherwise relatively independent units.
    Sasha Goldshtein | http://blogs.microsoft.co.il/blogs/sasha
    • Marked as answer by jack 321 Wednesday, June 4, 2008 2:22 AM
    Sunday, June 1, 2008 6:23 PM

All replies

  • Personally I only really use InternalsVisibleTo for unit tests; note that either way it doesn't really give you much safety - it isn't hard to bypass private/internal modifiers via reflection. And note that the IDE doesn't support circular references (if A references B, B can't reference A). If you need smoething close to circular, you'd be better off using a 3rd assembly to define some interfaces and use a "dependency injection" / "inversion of control" approach to expose the methods of each via interfaces.


    Marc
    • Marked as answer by jack 321 Wednesday, June 4, 2008 2:22 AM
    Saturday, May 31, 2008 8:23 AM
  • To answer your question, you can use [InternalsVisibleTo] across your application assemblies.  This has nothing to do with hacking, as Marc pointed out, because accessibility modifiers are not enforced by the runtime.

    The primary reason to avoid [InternalsVisibleTo] is that it encourages coupling between assemblies, that are otherwise relatively independent units.
    Sasha Goldshtein | http://blogs.microsoft.co.il/blogs/sasha
    • Marked as answer by jack 321 Wednesday, June 4, 2008 2:22 AM
    Sunday, June 1, 2008 6:23 PM
  • Sasha,

     

    I am not too worried about coupling.  I have a MVC model and MC are in my main assembly, while the views will me in a few other assemblies, one for the main app, one a VSTO assembly, a programmers gateway, and possibly a server based "View" interface...

    So I have broken up the view from the Model and Controller and that is where I decoupled them...

    Thanks for the input!

    Bob

    Wednesday, June 4, 2008 6:29 AM