Shuang Fan
Shuang Fan

Reputation: 121

The type 'Color' exists in both "corecompat.system.drawing and system.drawing.primitives

error message is 严重性 代码 说明 项目 文件 行 禁止显示状态 错误 CS0433 类型“Color”同时存在于“CoreCompat.System.Drawing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c0a7ed9c2333b592”和“System.Drawing.Primitives, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”中 End C:\Users\root\source\repos\End\End\Controllers\HomeController.cs 199 活动的

Upvotes: 0

Views: 5850

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062550

If this is talking about namespace collisions, then: you just need to qualify which Color you are talking about. You can do this either by:

  • removing any unnecessary using directives
  • using a using alias directive to explicity tell it which Color should mean in that file, i.e.

    using Color = CoreCompat.System.Drawing.Color;
    
  • fully qualifying the type when used, i.e. instead of Color foo, use CoreCompat.System.Drawing.Color foo.


If this is talking about the same namespace qualified type (i.e. both are in the same namespace), then: you're going to have to drop one of the assemblies, or use "extern alias". In the VS IDE you can set the "aliases" of each dll in the property window. The default is global. By setting specific aliases against each, you can import those aliases - for example, if you add "primitives" as an alias, you can add (at the top of your C# file):

extern alias primitives;

That might be enough by itself, but if not, you can use alias qualified names:

primitives::CoreCompat.System.Drawing.Color

(which is CoreCompat.System.Drawing.Color in the alias set described by primitives)

Upvotes: 4

Related Questions