Forum Xamarin.Forms

How to using a specific class between two classes which havs the same NameSpace?

Picture Below.
There are two "Encoding" classes sharing ONE NameSpace and I need the "Method" from the first "Encoding" Class. However, the secend "Encoding" class is alwsys default to use and I can't use the first one. What should I do?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    There are two "Encoding" classes sharing ONE NameSpace

    Stop. You know that's not possible in C#. You can't have two classes of the same name in the same namespace. You can't make two 'Mammal' classes in the same namespace. Try it. Visual Studio will yell at you for it.

    Your screenshot shows them in two different namespaces. You should be able to use the fully-qualified name to reference one or the other.

  • JiaxiangWangJiaxiangWang USMember

    @ClintStLaurent
    Thank u for your answer. But I think my situation is a little complicated...



    As you see, there is indeed two "System.Text" namespace with different version from different directory....
    So how can I chose specific one of that to use?

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    WTF? Did you have to do something special to force that? I see you have several like that. Are you bouncing this solution back and forth between VS2015 and VS2017? Maybe they each use a different one?

    Regardless what files you have, C# just won't allow two classes of the same name in the same namespace. It can't. There is no way to differentiate one from the other. Regardless where the files live the assembly.namespace.classname is what matters at compile time.

    You might have references to them... maybe for different build configurations... meaning one is used when you build profile 111 for example, and one is used by the iOS app only. Or something similar. But its just not possible to have them both **active ** at the same time in the same assembly.namespace

    I'd pretty much bet that these are either in different assemblies, or that come compile time only one is actually compiled into your app.

  • JiaxiangWangJiaxiangWang USMember

    @ClintStLaurent
    That's very very confusing. It occurred to me that VS told me that Xamarin project need "microlib.dll" v2.3 but mine is "microlib.dll" v4.0 and they are not compatible blabla... In fact, microlib 2.3 exists in project folder and the microlib v4.0 is from my C disk...
    But I really don't know how to choose the microlib.dll for project...

Sign In or Register to comment.