|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
following of thread: "Adding namespaces to code behind automatically" More optionsHello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I have a newer problem which seems to come from the fact that the assembly which contains my "SimpleComponentToolboxItem" must be already referenced in the project where I want to insert my control. I have a usercontrol, which uses a TagListViewToolboxItem and its CreateComponentsCore method to reference other assemblies to the project where I insert my control. like this: (In the library xyz.dll) [System.ComponentModel.ToolboxItem(false)] [Serializable] public class MYTagListViewToolboxItem : ToolboxItem { /// <summary>Not used...</summary> public MyTagListViewToolboxItem() : base() { } private MyTagListViewToolboxItem(SerializationInfo info, StreamingContext context) : base(typeof(MyControls.MyTagListView)) {Deserialize(info, context); } protected override IComponent[] CreateComponentsCore(IDesignerHost host) { MessageBox.Show("1"); ITypeResolutionService service1; IComponent component1; IComponent[] componentArray1; IContainer container1 = host.Container; service1 = ((ITypeResolutionService)host.GetService(typeof(ITypeResolutionService))); string assPath = "C:\\MyAssemblies"; string ass1Name = assPath + "\\log4net.dll"; string ass2Name = assPath + "\\Util.dll"; System.Reflection.Assembly ass1 = System.Reflection.Assembly.LoadFrom(ass1Name); System.Reflection.Assembly ass2 = System.Reflection.Assembly.LoadFrom(ass2Name); service1.ReferenceAssembly(ass1.GetName()); service1.ReferenceAssembly(ass2.GetName()); component1 = (IComponent)System.Activator.CreateInstance(Type.GetType(this.TypeName)); container1.Add(component1); componentArray1 = new IComponent[] { component1 }; return componentArray1; } } I have the assembly loaded in the VS8 Toolbox and this implementation works fine when the project where I want to drag-and-drop the MyTagListView control already has a reference to my library xyz.dll, which contains my toolboxitem class. But if the project does not already reference the xyz.dll assembly, I get the following error while trying to insert my control on the form: "Failed to create component 'Component'. The error message follows: 'The toolbox item could not be retrieved from the toolbox. Make sure the assembly that contains the toolbox item is correctly installed. The toolbox item raised the following error: Object reference not set to an instance of an object." .... and my control is not inserted. I thought that this was because the control type set in the private constructor was not known by the project. But then I have replaced my MyTagListView control to a normal Button control (still in this private constructor, and the problem still occured. This tells me that the assembly which contains my toolboxitem MUST be referenced in the project before being able to use the control from the toolbox. I have also put some messagebox in the private method, and found out that having just the mouse over the toolboxitem of my control will instanciate my toolboxitem. If this cannot be fixed, it means that I absolutely need to reference my xyz.dll assembly to the project before being allowed to insert my controls in the form. I have tried many things, and I must say that I am short of arguments... . Thank you in advance for your help, Jean-Francois |
|||||||||||||||||||||||