Groups | Blog | Home
all groups > dotnet windows forms designtime > march 2004 >

dotnet windows forms designtime : UITypeEditor must be in the same assembly?



Ben R. Bolton
3/31/2004 7:07:25 PM
I have a WebControlLib project that defines a custom property editor which
works well for a property of a custom control in the WebControlLib assembly
but when I move the custom property editor class to different assembly the
IDE won't run the editor for the property.

The attribute for the property that I have been using is:

[
Editor(typeof(CustomEditor),typeof(UITypeEditor))
]

I, of course, had to add a reference to the new assembly (ClientLib.)

Do custom editors have to be defined in the same physical assembly as the
property that uses it?

I would like to move this custom editor out to a different assembly and make
it available to other projects. Does anyone have any suggestions on how
this can be done?

Ben

Palo Mraz
4/6/2004 12:34:32 PM
Hi Ben,

I've made it work with WinForms designer, but hopefully it will
work with WebForms designer as well. Here are the steps I've used:

1. In your WebControlLib library, use the EditorAttribute constructor
that accepts the string type name of the type editor, e.g.:
[Editor("ClientLib.CustomEditor", typeof(UITypeEditor))]

2. In your ClientLib design library, add an *assembly* reference to
your WebControlLib from the appropriate output directory.

3. In order to debug the design time functionality of your editor,
you'll have to ensure that VS is able to locate your design assembly.
You'll have to either place the ClientLib.dll into the devenv.exe folder.
Or you could add the appropriate <dependentAssembly> and
<codeBase> settings pointing to your ClientLib assembly to the
devenv.exe.config file (this is the approach that I've used with my
WinForms design library). (Or you could place the design assembly
into GAC (provided it has a strong name), but I wouldn't recommend
that.)

Best regards,

Palo
--
http://dact.lamarvin.com/
AutoComplete component for WinForms applications. Easy to integrate, easier
to use!
http://www.vbinfozine.com/
An ordinary VB developer shares his own successes and failures

Ben R. Bolton
4/8/2004 9:30:43 AM
Thanks Palo,

1) I've had problems with using typeof to get a type at compile time that
doesn't work at design time before. Can you explain why using

[Editor("ClientLib.CustomEditor", typeof(UITypeEditor))]

works, while

Editor(typeof(CustomEditor),typeof(UITypeEditor))

compiles but has problems at run-time?

2) I don't quite understand the suggestion for a reference. CustomEditor is
defined in ClientLib and the control is in WebControlLib, therefore there
must be a reference to ClientLib in the WebControlLib project, creating
reference to WebControlLib from ClientLib would create an invalid reference.
Do you mean something different by an *assembly* reference?

Again, thanks for your assistance.

Ben


[quoted text, click to view]

Palo Mraz
4/14/2004 11:40:50 PM
[quoted text, click to view]

Could you be please more specific? What kind of problems at runtime
do you have?

[quoted text, click to view]

The point here is that your designer assembly (ClientLib) references your
control
assembly (WebControlLib), but your control assembly *doesn't* reference your
designer assembly. This way, the control assembly doesn't have the designer
assembly
as a dependence in its manifest, so it should be loaded and executed with no
problems
at runtime. At design time, when the VS.NET designer host instantiates your
control,
it will try to instantiate the designer based on its the type name, as
specified by the
EditorAttribute attribute. Therefore, the designer assembly has to be
available to the
executable, which devenv.exe.

Obviously, the designer has to communicate with the control somehow . If
they're in the
same assembly, they can use Friend (internal) methods. But if they're
separated *and*
the control assembly doesn't know anything about the designer (except its
string type name),
there must be some mechanism how the designer communicates with the control
being
designed. Because the designer assembly *does* reference the control
assembly, it can
use the control's public interface. If the designer wants to employ some
"nonpublic"
exchanges with the control during design time, I'd suggest defining an
EditorBrowsable(Never)-interface defined in the control's assembly, which
the designer
assembly could use. If you'd like to be secure, you could probably sign your
assemblies
and apply the StrongNameIdentityPermission to the designer-only interface
methods (as
explained in
http://msdn.microsoft.com/msdnmag/issues/04/04/SecurityBriefs/default.aspx),
but
I don't have practical experience with it.

HTH

Best regards,

Palo
---
http://dact.lamarvin.com/
AutoComplete component for WinForms applications. Easy to integrate, easier
to use!
http://www.vbinfozine.com/
An ordinary VB developer shares his own successes and failures

AddThis Social Bookmark Button