Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c# - CS0436: Type conflicts with the imported type

I am including an instance of the same source files in multiple assemblies using the Add As Link option. I specifically need to include an instance of the same source within these assemblies because it is responsible for licence validation which must occur internally to the assembly. Performing licence calls across module boundaries could introduce a security risk.

Some of the projects in my solution that include the code depend on other modules that also include it, resulting in warning CS0436:

"The type [type] in [licence.cs full path] conflicts with the imported type [LicenceClass] in [dependency project also including licence.cs]. Using the type defined in [licence.cs full path]".

I have tried declaring a class alias, but the definitions internal to licence.cs cause the same warning. In the alias, there must be a reference to the duplicated class name which causes the same warning.

I know it is bad practice to duplicate source between assemblies, but it is intentional in this case. I would rather keep a central instance that each assembly links to rather than a dedicated instance with renamed classes to avoid the warnings.

The workaround I have is simply to ignore the warning using a #pragma. Is there a more elegant solution?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is worth noting that another way to get such warnings is by simply setting a project in visual studio to reference itself: References -> Solution -> etc etc (how I figured this gem out is left as an exercise to the reader ...)

Visual Studio will happily comply, only to throw a wall of warnings of the type described by OP during build, which is to be expected (upon reflection) since every single class etc is getting defined twice.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...