3

The iTextSharp assembly includes the BouncyCastle namespace in the core assembly, but the VB.Net application I am working with uses a different version of BouncyCastle already. I think C# could work around this by using "extern alias" but I can't find how to do this in VB.NET.

Is there any equivalent of extern alias in VB.Net or any other way to exclude specific namespaces from a particular assembly?

Rattle
  • 2,393
  • 2
  • 20
  • 25
  • Are you asking how to use 2 different versions of the same assembly in your app? If not, the answer is to NOT import the namespaces globally but to refer to the full path everytime. For example, TEXT is a popular namespace that lives in many assemblies. When I want something like the StringBuilder assembly, I have to prefix with the full name `System.Text.StringBuilder`, as an example. Is this what you're needing? – Steve Nov 17 '14 at 19:38
  • You were right the first time - the application needs to use two different versions of the same classes, but where the classes are defined in two different assemblies. For now I seem to be able to get by only using the second version throughout the application. – Rattle Nov 20 '14 at 17:07

1 Answers1

1

You can alias your namespaces in the import like this:

Imports [ aliasname = ] namespace
-or-
Imports [ aliasname = ] namespace.element

IE

Imports strbld = System.Text.StringBuilder
Imports dirinf = System.IO.DirectoryInfo

Public Function GetFolders() As String 
    Dim sb As New strbld

    Dim dInfo As New dirinf("c:\")
    For Each dir As dirinf In dInfo.GetDirectories()
        sb.Append(dir.Name)
        sb.Append(ControlChars.CrLf)
    Next 

    Return sb.ToString
End Function

See MSDN reference for full info: http://msdn.microsoft.com/en-us/library/7f38zh8x.aspx

Steve
  • 5,585
  • 2
  • 18
  • 32
  • I think this solution is for using identically named classes from different namespaces, my issue was where the same namespace is defined in two different assemblies. – Rattle Nov 20 '14 at 17:12