Search code examples
c#asp.netvb.netvisual-studiovisual-studio-2015

Warning CS0436 suddenly appears when upgrading to VS2015


I've just upgraded from VS2013 to VS2015, and a ton of CS0436 warnings have appeared, all seemingly relating to the same issue.

I am slowly migrating web applications from VB to C#, so perhaps this is something really simple. I'm new to C# so please use layman-type answers...

My solution is structured as such:

Project 1 - Reusable methods (database access, etc)

\CommonDataAccessFunctionality.vb

Namespace MyCompany
    Public Class CommonDataAccessFunctionality
        Public Sub New(ByVal storedProcedureToRun As String)
            ' db stuff here '
        End Sub
    End Class
End Namespace

Project 2 - Web Applicable (C#) with dependency on Project 1

App_Code\DataAccess.cs

using System.Data;
using System.Data.SqlClient;

namespace QrCodes.App_Data
{
    public abstract class QrDataCommon : MyCompany.CommonDataAccessFunctionality
    {
        public QrDataCommon(string storedProcedureToRun)
            : base(storedProcedureToRun)
        {

        }
    }

    public class QrDataGrabber : QrDataCommon
    {
        public QrDataGrabber(string storedProcedureToRun)
            : base(storedProcedureToRun)
        {
    }
    }
}

The error is shown on this line:

public class QrDataGrabber : QrDataCommon

Warning CS0436
The type 'QrDataCommon' in 'D:\Web\wwwroot\MyApp\MyApp-InProgress-Person WebApi\QrCodes\App_Code\DataAccess.cs' conflicts with the imported type 'QrDataCommon' in 'QrCodes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'D:\Web\wwwroot\MyApp\MyApp-InProgress-Person WebApi\QrCodes\App_Code\DataAccess.cs'.

I've read many posts on here about a project referencing itself, however, there are no references in the project dialog (that are listed), only a single dependency in Project 2 to Project 1. Also, Project 2 has no controls, etc, that reference anything else.

Can anyone please give me some guidance? I'm not sure if its helpful, but in the object browser when searching for 'QrDataCommon' I see this:

enter image description here

Update based on help so far

If I opt to view all files within Solution Explorer, within the \bin\ directory there is a file called QrCodes.dll that gets created when the project/solution is built. I also see the same in the hidden Debug folder.

If I rename the QrDataCommon class to something totally unique, say QrDataCommonTest123, and clean/rebuild, the error immediately updates to use the new class name.

Therefore, might this be something to do with the application build target location or something?


Solution

  • Warning CS0436 The type 'QrDataCommon' in '...DataAccess.cs' conflicts with the imported type 'QrDataCommon' in '...'. Using the type defined in '...DataAccess.cs'.

    Most people likely run into this because of projects referencing themselves (as you pointed out); however, in your case it's because your VB project has a type with exactly the same namespace and name - a result of doing a direct 1:1 port from VB to C#.

    Due to the name and namespace being identical C# has a choice to make: which one should it use? It is informing you that it is made the most logical choice and has chosen the one in your C# project - which is probably what you wanted it to do anyway.

    These are your options:

    • Good option: Once you have completed porting a type to C# delete it from the VB project and recompile the VB project.
    • Good option: If you are not distributing your code as a standalone re-usable DLL (it looks like you are not), change the root namespace of your C# code.
    • Ignore the error until you have completed the port.
    • Worst option: Use a global namespace alias.