Omnisharp-vscode: The namespace already contains a definition for class name [netcoreapp1.0]

Created on 6 Oct 2016  路  4Comments  路  Source: OmniSharp/omnisharp-vscode

Environment data

dotnet --info output:
.NET Command Line Tools (1.0.0-preview2-003131)

Product Information:
Version: 1.0.0-preview2-003131
Commit SHA-1 hash: 635cf40e58

Runtime Environment:
OS Name: Mac OS X
OS Version: 10.11
OS Platform: Darwin
RID: osx.10.11-x64

VS Code version: 1.5.3
C# Extension version: 1.4.1

Steps to reproduce

Creating a class that inherits from another class.

Code used to create bug:

Animal.cs

using System;

namespace Zoolandia {
    public class Animal
        {
            public string Type { get; set; }
            public string Name { get; set; }
            public string Height { get; set; }
            public string Weight { get; set; }
            public int NumOfLegs { get; set; }

            public static void Sleep ()
            {
                Console.WriteLine("Animal is now sleeping");
            }

            public virtual void Init(){}

            public virtual string SayGreeting()
            {
                return $"I am an animal!";
            }
        }
}

CarassiusAuratus.cs

namespace Zoolandia {
    // https://en.wikipedia.org/wiki/Goldfish
    public class CarassiusAuratus : Animal
    {
        public CarassiusAuratus()
        {
            this.HasScales = true;
            this.CanSwim = true;
            this.Name = "Goldie";
            this.Init();
        }
        public CarassiusAuratus(string name = "Goldie")
        {
            this.HasScales = true;
            this.CanSwim = true;
            this.Name = name;
            this.Init();
        }
        public CarassiusAuratus(int legs = 0)
        {
            this.HasScales = true;
            this.CanSwim = true;
            this.NumOfLegs = legs;
            this.Init();
        }

        public CarassiusAuratus(string name = "Goldie", int legs = 0)
        {
            this.HasScales = true;
            this.Name = name;
            this.NumOfLegs = legs;
            this.Init();
        }
        public bool HasScales { get; set; }
        public bool CanSwim { get; set; }
        public override void Init()
        {
            this.Type = "Carassius Auratus";
        }

        public override string SayGreeting()
        {
            return $"Hello, my name is {this.Name}! I am a {this.Type} and I swim! {base.SayGreeting()}";
        }
    }
}

Program.cs

using System;
using System.Collections.Generic;

namespace Zoolandia
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Let's make some animals!
            // No animals were harmed in the writing of this program.
            List<Animal> myAnimals = new List<Animal>();

            CarassiusAuratus myGoldie = new CarassiusAuratus("Goldie");

            myAnimals.Add(myGoldie);

            foreach(Animal myAnimal in myAnimals)
            {
                Console.WriteLine(myAnimal.SayGreeting());
            }
        }
    }
}

image
image

image

Expected behavior

No red squiggle underline

Actual behavior

Red squiggle underline but compiles and runs properly without any errors or warnings.

Bug Resolved-Duplicate

Most helpful comment

I've got the same issue. As soon as the class is wrapped by a namespace, I receive the visual error "The namespace ... already contains a definition for ... [netcoreapp1.0]"

All 4 comments

This looks very similar to #785. Is that the same issue?

@DustinCampbell This could very well be the same issue. I do recall renaming a file or two while writing the code shown above.

I've got the same issue. As soon as the class is wrapped by a namespace, I receive the visual error "The namespace ... already contains a definition for ... [netcoreapp1.0]"

We're going to use https://github.com/OmniSharp/omnisharp-vscode/issues/785 to track fixing this issue.

Was this page helpful?
0 / 5 - 0 ratings