Third party library polluting the top level namespace; any way to stop it? RRS feed

  • Question

  • I have a third party library (a .NET wrapper around a C++ library) which is rather oddly built. It contains several namespaces, but it also contains several entities that are in no namespace at all. Unfortunately, they're garbage, and even worse, two of them are structures named "attribute" and "ecxeption," which are naturally conflicting with System.Attribute and System.Exception as soon as I reference the DLL.

    Is there some way to reference the assembly such that only the namespaced items get brought in, or force a namespace around the whole assembly to contain the global garbage?

    Quidquid latine dictum sit, altum sonatur
    Thursday, February 4, 2010 7:52 PM


All replies

  • I don't think it is possible. If it is then it is a feature of Visual Studio IntelliSense, not CLR.

    Saturday, February 13, 2010 11:51 PM
  • > force a namespace around the whole assembly to contain the global garbage?

    Good news, the C# compiler actually supports this!

    1.  Add the reference to your project, then highlight it in the Solution Explorer window.
    2.  Change the Aliases property in the Properties window from "global" to the name you want to use for the wrapper namespace.  For example, "Wrapper".
    3.  In the .cs file where you are call the library, put "extern alias Wrapper;" at the top.  This will make the wrapper namespace usable in that source file.
    4.  Now you will be able to qualify identifiers in that library with the wrapper namespace, for example: Wrapper.ClassName.  (Note:  Since Wrapper is an alias, the syntax of using :: instead of . is also supported.  In unusual cases where there is a name conflict, :: must be used instead of .)

    The documentation for "extern alias" is here.  The documentation includes details on how to do this if you are running the compiler (csc.exe) directly.
    Sunday, February 14, 2010 12:08 AM
  • i don't know if this would work but it may be worth looking at.  C# Station shows aliases being used with using directives for namespaces.  Aliasing the conflicting namespaces may prevent the issue when using them.  I don't know if this would work but thought it might be worth looking at.

    Sunday, February 14, 2010 1:14 AM