How can I use a specific NameSpace between two same-name namespaces from different directory?

JiaxiangWangJiaxiangWang USMember

Hey guys, I need the "Encoding" class from "microlib" but the second "Encoding" is default to use. What should I do?

Best Answer

  • HunumanHunuman GB ✭✭✭✭
    Accepted Answer

    hi @JiaxiangWang

    Not sure I fully understand, but assuming you are trying to use 2 different versions of the same assembly:
    Use the the Full Assembly Qualified Type Name to instantiate the Type you need.

    A fully qualified Type name looks like this:

    "WackyCars.ViewModels.CarsViewModel, WackyCars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    Use it something like this:

                       Type oType = Type.GetType(AssemblyQualifiedTypeName.Trim());
                       if (oType != null)
                       {
                           //Got Type so create instance
                           object asmObj = Activator.CreateInstance(oType, TypeConstructorArgs);
    
                           if (asmObj != null)
                           {
                               //use the object
                            }
                         }
    

    Please see here for details.

    Hope this points you in the right direction,

    Tim

Answers

  • HunumanHunuman GBMember ✭✭✭✭
    Accepted Answer

    hi @JiaxiangWang

    Not sure I fully understand, but assuming you are trying to use 2 different versions of the same assembly:
    Use the the Full Assembly Qualified Type Name to instantiate the Type you need.

    A fully qualified Type name looks like this:

    "WackyCars.ViewModels.CarsViewModel, WackyCars, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

    Use it something like this:

                       Type oType = Type.GetType(AssemblyQualifiedTypeName.Trim());
                       if (oType != null)
                       {
                           //Got Type so create instance
                           object asmObj = Activator.CreateInstance(oType, TypeConstructorArgs);
    
                           if (asmObj != null)
                           {
                               //use the object
                            }
                         }
    

    Please see here for details.

    Hope this points you in the right direction,

    Tim

Sign In or Register to comment.