开发者

Can an assembly that includes a non-CLS-compliant reference be CLS-compliant?

I have an existing DLL that is not CLS-compliant that I reference from my own project. When I mark my assembly as CLS-compliant, I get compiler warnings that names in the referenced assembly are not CLS-compliant.

Is there a way I can keep my assembly CLS-compl开发者_开发知识库iant and mark the referenced one as not?


Yes, your DLL can be CLS-compliant as long as it doesn't expose any non-CLS-compliant members from the referenced assembly -- that is, it doesn't mention them in any of its own public or protected members or types. (It can still use them in private and internal members and types.)

If your DLL does need to expose types directly from the non-compliant DLL, you can either try encapsulating those types in your own wrappers (e.g. a method might return a MyWrapperAroundNaughtyType instead of a NaughtyType), or you can mark the relevant members of your API CLSCompliant(false) to opt just those members out of compiler checking.


What I ended up doing because the other suggestions didn't work was setting the property Embed Interop Types of the referenced dll (with the non-CLS-compliant members) to false.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜