Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CS0433 The type 'type' exists in 'ProjectA' and 'ProjectB'

I have a solution made with .NET Framework 4.7 (c#) in which we have 2 projects that contain the same partial class within the same namespace, those projects are packaged on a nupkg.

From now on we will follow the following logic:

  • Project A: has a part of the partial class and reference to Project B
  • Project B: has another part of the partial class (code generated automatically)
  • Project C: this project has the nupkg referenced but if we try to call any property of the mentioned class when compiling, it gives the following error:
    CS0433 The type 'Config' exists in 'ProjectA, Version=1.2023.2.21, Culture=neutral, PublicKeyToken=null' and in 'ProjectB, Version=1.2023.2.21, Culture=neutral, PublicKeyToken=null'

I’ve already tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • Cleaning and rebuilding.
  • Deleting and adding again the references.
  • Removing redundant and useless references.
  • Uninstalling the NuGet from Project C and installing it again.

Here are the conflicting code snippets in each project:

Project A: partial class Config

namespace WhatIsWrong
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;

    public partial class Config
    {
    }
}

Project B: partial class Config

namespace WhatIsWrong
{
    using System;
    using System.Collections.Generic;

    public partial class Config
    {
        public string parameter { get; set; }
        public string value { get; set; }
    }
}

Project C

public DbSet<WhatIsWrong.Config> Config { get; set; }

>Solution :

Project A: has a part of the partial class and reference to Project B
Project B: has another part of the partial class (code generated automatically)

That’s not how partial classes work. What you’ve got there is two classes in two projects.

Every part of a partial class needs to be in the same project, because they’re compiled together to be one type.

Partial classes allow a single type’s code to be distributed amongst multiple files – but not multiple projects.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading