Warning “The type X in Y.cs conflicts with the imported type X in Z.dll”

后端 未结 9 974
Happy的楠姐
Happy的楠姐 2021-01-03 17:41

The main.cs of my project returns the following warning:

Warning 1 The type \'Extensions.MessageDetails\' in \'PATH\\Extensions.cs\'

相关标签:
9条回答
  • 2021-01-03 18:23

    If you really need to have both classes declared or referenced in two separate dll, you can mark your class as internal.

    Internal types or members are accessible only within files in the same assembly, therefore it will prevent the collision.

    0 讨论(0)
  • 2021-01-03 18:24

    It seems like Extensions.cs is both part of the project that builds lib.dll and your main.exe

    Remove it from one of the project to fix this issue.

    0 讨论(0)
  • 2021-01-03 18:31

    I had this kind of issue where I had reverted from a target .NET Framework version of 4.5.2 to 4.0.

    Classes in my App_Code folder had methods that called methods in other classes in that folder. When I created a standard folder I named "AppCode", and moved my classes into it, I no longer had the issue.

    If I re-created the "App_Code" folder and move my classes back into it, I will have this issue again. I'm convinced it has to do with my .NET Framework version or that Visual Studio just doesn't deal well with changing it after being initially built/targeted to another version.

    0 讨论(0)
提交回复
热议问题