开发者

Conflicting types present in two Silverlight dlls

开发者 https://www.devze.com 2023-04-07 02:44 出处:网络
Scenario: I have created two custom controls in Silverlight, MyC开发者_StackOverflow中文版ustomControl1 and MyCustomControl2. Both the controls have a namespace called Control.Generic. Control.Generi

Scenario:

I have created two custom controls in Silverlight, MyC开发者_StackOverflow中文版ustomControl1 and MyCustomControl2. Both the controls have a namespace called Control.Generic. Control.Generic has an enum type called PageOrientation. I want to use both the controls (MyCustomControl1 and MyCustomControl2) together in my project. I have added references to these two controls in my project. Now, how can I include the namespace Control.Generic for both the controls in my class file? Currently I have specified it as shown below:

using Control.Generic;

But the problem is when I am using the PageOrientation enum, I am getting the following exception.

The type 'Control.Generic.PageOrientation' exists in both 'MyCustomControl1.dll' and 'MyCustomControl2.dll'.

How can I resolve this conflict?


It is common to want to share classes/enums etc between your user controls. You should avoid having the exact same fully-qualified name in any two libraries.

What you want to do is have a common library, referenced by both user control libraries, containing any common elements you may want to reuse.

e.g.

Controls.Generic.dll contains Control.Generic.PageOrientation and MyCustomControl1.dll and MyCustomControl1.dll simply reference Controls.Generic.dll.

As a rule your libraries and namespaces within them should match. If they don't you are probably trying to do something you shouldn't :)

Basically start treating your own libraries like third-party controls and use naming standards like they do (company.subarea.featureset etc). It will save you a lot of trouble in the long run.

0

精彩评论

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

关注公众号