Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
C# Referenced Namespace Hidden By Class Namespace

I have a class like this:

namespace Token1.Token2.Token3
{
    public class Class1
    {
    }
}

And another class like this:

namespace Token2.Token4.Token5
{
    public class Class1
    {
    }
}

The first class is a part of my project, the second class is from a framework library developed by another group within my organization. Notice the namespace of the first class has Token2 in the second place and the namespace of the second class has Token2 in the first place.

The problem I am having is that I can't seem to reference the second class within the first because of what looks like a namespace collision. If I try to do this in the first class:

namespace Token1.Token2.Token3
{
    public class Class1
    {
        var frameworkClass1 = new Token2.Token4.Token5.Class1();
    }
}

the Visual Studio IDE highlights Token4 in red and says "Cannot resolve symbol 'Token4'". If I hover my mouse over Token2 where I am new'ing up Class1, intellisense shows me "namespace Token1.Token2" so it is clearly seeing the namespace of my project class and not seeing the namespace of my framework class.

It would be very difficult to change the namespace of either class library due to the amount of code already in place. Is there a way to get around this?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Since Token2 is also a sub-namespace of Token1 you need to specify that you're looking for the "root" namespace:

var frameworkClass1 = new global::Token2.Token4.Token5.Class1();

You could also alias it with a using statement:

using Token5 = global::Token2.Token4.Token5;

And then just reference the alias:

var frameworkClass1 = new Token5.Class1();
over 4 years ago · Santiago Trujillo Relatório

0

You could try global::Token2 for the framework namespace

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda