tags:

views:

150

answers:

1

I have an extensibility library (or the start of one), with a UITypeEditor. I'd now like to decorate the property with the EditorAttribute. I don't want to reference the extensibility library, as it does not need to be deployed, so I'm using this:

[Editor("MyProject.Extensibility.MyUIEditor, MyProject.Extensibility, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", typeof (UITypeEditor))]
MySpecialType SpecialType { get; set; }

This doesn't work. The type editor is for use on enums and when I use this, the standard enum drop down is shown. However, if you copy the type editor into the project and use a direct type reference, all works well. I've tried testing my string using Activator.CreateInstance and I've got that to work. The MyProject.Extensibility.dll is copied into just about every where (all the project's bin/debug folders). Is there some special place to put an extensibility dll so .net can resolve the assembly?

Thanks!

+2  A: 

Just enter Regedit.exe and create a key just like:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v2.0.50727\AssemblyFoldersEx\StackOverflow

It doesn't really matter what the name of the key is, all folder names listed within AssemblyFoldersEx are searched for Assemblies design-time by Visual Studio.

A folder must be added in Regedit using a (Default) entry having the folder path as value. (See sibling keys for example).

It's interesting that all folders present in the AssemblyFoldersEx registry key will automatically also appear when you click "Add New Reference" on a project context menu on the .NET tab.

Another approach would be to add the desired assembly to Global Access Cache (c:\Windows\Assembly)

I just made the following test: On a resource assembly I put the following code:

public class MyEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        MessageBox.Show("Works");
        return null;
    }
}

On the consumer assembly (Windows forms executable assembly) I created a component that derives from Button just like this:

public class MyButton : Button
{
    [Editor("AssemblyReferenceCL.MyEditor, AssemblyReferenceCL", typeof(UITypeEditor))]
    public String MyProp { get; set; }
}

There's no reference between the two assemblies. Everything worked just fine.

Ciwee
Thanks! The MessageBox.Show didn't work in my attempt, kept getting a null reference exception. However, I did get a modal editor working, in another project, no references using the registry setting. Again thanks!
Greg McGuffey