Resolved Property Inheritance throwing CS0299

DebashshishSaha

New member
Joined
Jan 24, 2021
Messages
3
Programming Experience
3-5
c#:
using System;
using System.Collections.Generic;

namespace CovariantAssignment
{
    class Program
    {
        static void Main(string[] args)
        {
            Apple apple = new Apple() { Name = "" };
        }
    }
    public class Fruit
    {
        public string Name{ get; set; }
    }
    public class Apple:Fruit
    {
        public string Color { get; set; } = "Red";
    }
    public class Guava : Fruit
    {
        public string Color { get; set; } = "Green";
    }
}


1611488786773.png

1611488832160.png


this only resolves if I make the property protected .
Can anyone please explain why ?
 
Last edited:
Firstly, please don't post pictures of code or error messages, or at least not ONLY pictures. Both are text so post them as text, formatted appropriately. We will often need to use them ourselves to test or search and we should be able to copy and paste, not type it out again for ourselves.
 
As for the issue, unless something is corrupt, there must be something else going on that you haven't shown us, because that code would not generate that error. Perhaps you should show us the three warnings as well, because they seem to refer to some code you haven't shown and may shed some light on the error.
 
This is the only code that generating this error . Other warning are coming from my other projects . May be if you could just copy and paste on your IDE, and let me know if you get the same error
 
Surprisingly, I just deleted that project and created a new one , with same code . I am not getting this error again :) .
You're right @jmcilhinney . the project might have been corrupted . thanks for your time . I was also shocked to see this .
 
You may see this sort of thing from time to time. Hopefully very rarely though. I've seen similar issues with no idea of the specific cause, but nothing like that for a long time.
 
I hope that C# projects don't start spontaneously getting corrupted.

I've only seen that sort of thing with C++ projects. Somehow the project would just spontaneously become corrupt after weeks of successful use. It's why for C++ project, I just typically build on the command line and never trust the Intellisense errors and warnings.

For C# projects, I've only seen it when in the older versions of Visual Studio in conjunction with people incorrectly using source control where they would also check in the .SUO files and/or other files that meant to be per user files not meant to be put into source control. In newer versions of VS, it would be someone checked in the .vs directory. It would also happen in non-source control situations when people would tree copy on project and paste it to another location, and then start renaming or pruning stuff. Basically, it was all user induced and not something spontaneous.
 
I hope that C# projects don't start spontaneously getting corrupted.
It happened me a few days ago. Just glad I kept a copy of the code on the server. I stopped syncing, and deleted the local code and downloaded the project from the server. All was fine then. Strange eh? Hope it was a one off. One of the reasons I moved to Python...
 
That's not a good sign... I hope someone opens an issue or two in community voice along with the needed logs or snapshots of the project directory to help MS fix things.
 
Back
Top Bottom