Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The namespace already contains a definition for class name [netcoreapp1.0] #803

Closed
matthamil opened this issue Oct 6, 2016 · 5 comments
Closed

Comments

@matthamil
Copy link

matthamil commented Oct 6, 2016

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.

@DustinCampbell
Copy link
Member

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

@matthamil
Copy link
Author

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

@ghost
Copy link

ghost commented Nov 1, 2016

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]"

@DustinCampbell
Copy link
Member

We're going to use #785 to track fixing this issue.

@exeptionerror
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants