|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Adding @Assembly references programmaticallyIs there any way to add the @Assembly reference to the aspx files programmatically from inside a custom control (when it gets dropped on to the page from the toolbox)? I have a custom control - MyControl that implements an interface in another custom assembly - InterfaceAssembly. When MyControl gets dropped on to the page and run, it results in a "InterfaceAssembly not found" exception. I am aware that this can be fixed by manually adding a @Assembly directive refering to the InterfaceAssembly in the GAC (or add a reference to it in the web.config/machine.config, etc) - but that is not good enough. The MyControl is a control that will be distributed to a whole lot of people and we do not want them to do this manual step every time they drag and drop this control to a page - not very elegant. I see that Steven Cheng from MS has responded to some related issues in the newsgroups. Hope to hear from him or someone else from MS. Thanks in advance, Praveen If it's a user control, then you can add the @Assembly directive to the ASCX
file. If it's a custom control, then add the reference to the assembly via project references and then compiling your project. If it's in the App_Code directory, then add an assembly reference via web.config: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfassemblies.asp?frame=true -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > Hi, > > Is there any way to add the @Assembly reference to the aspx files > programmatically from inside a custom control (when it gets dropped on > to the page from the toolbox)? > > I have a custom control - MyControl that implements an interface in > another custom assembly - InterfaceAssembly. When MyControl gets > dropped on to the page and run, it results in a "InterfaceAssembly not > found" exception. I am aware that this can be fixed by manually adding > a @Assembly directive refering to the InterfaceAssembly in the GAC (or > add a reference to it in the web.config/machine.config, etc) - but > that is not good enough. The MyControl is a control that will be > distributed to a whole lot of people and we do not want them to do > this manual step every time they drag and drop this control to a page > - not very elegant. > > I see that Steven Cheng from MS has responded to some related issues > in the newsgroups. Hope to hear from him or someone else from MS. > > Thanks in advance, > Praveen Brock,
Thanks for the reply. But, like I mentioned I do not want to add the reference manually, I want my custom control to INSERT this AUTOMATICALLY into the aspx file in which it was added, if possible. Thanks -Praveen Thanks for Brock's inputs.
Hi Praveen, From the description of your problem, it is a VS.NET's design-time issue which I've met in some former issues. And is the following issue the one you found on the web search ? #Adding namespaces to code behind automatically (C#) http://groups.google.com.sg/groups?hl=en&lr=&selm=qzudX38aEHA.2752%40cpmsftn gxa06.phx.gbl&rnum=2 I think that's exactly the same problem as yours. When we developing a custom control and use VS.NET's ToolBox to drag it onto our page or winform. The VS.NET ide will automatcally add assembly reference of the control's Main Assembly(dll). However, if the control still have other assembly dependecy, VS.NET won't add them into references automatically. Then, if we didn't manually add them (in our project) or in our control's design-time code, there will occur assembly not found exception at runtime. That's just what you 've encountered, yes? Also, have you tried the sample code in the above thread? ==================== protected override IComponent[] CreateComponentsCore(IDesignerHost host) { ITypeResolutionService service1; Assembly assembly1,assembly2; IComponent component1; IComponent[] componentArray1; IContainer container1 = host.Container; service1 = ((ITypeResolutionService) host.GetService(typeof(ITypeResolutionService))); assembly1 = typeof(ClassLib.UserName).Module.Assembly; assembly2 = typeof(ComponentLib.SimpleComponent).Module.Assembly; service1.ReferenceAssembly(assembly1.GetName()); service1.ReferenceAssembly(assembly2.GetName()); component1 = new ComponentLib.SimpleComponent(); container1.Add(component1); componentArray1 = new IComponent[]{component1}; return componentArray1; } ================== We can override the CreateComponents method of the ToolboxItem and manually add the necessary assembly dependecy in it. The following two statements are just the adding reference code: service1.ReferenceAssembly(assembly1.GetName()); service1.ReferenceAssembly(assembly2.GetName()); Please have a look to see whether it helps. Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Hi Praveen,
After some further checking , I'm thinking the problem is likely environment specific or project specific. Based on my local test, (a control with another dependency), I didn't get the assembly not load error. I've tested using strong-named or not strong-named control assembly. As I also mentioned in another thread, if possible, you can generate a simplified version of your problem control and let me do some tests on my local side. Looking forward to your response. Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) Steven,
Glad to hear from you! Yes, the thread you posted in the other message is what I had referred to. The other message I posted is also, as you might have figured, related to resolving this issue. Before I generate a sample for you, could you please test the following. My custom control implements an interface defined in this other assembly - which is what is causing the runtime dll not found error. Does your test case do something similar (implementing an interface)? If not, please try that quickly. Now, if you can reproduce the above issue, then does providing a custom ToolBoxItem resolve the issue (by forcing a @assembly reference into the aspx page)? I will send a sample if you cannot reproduce the above. Thanks Praveen Show quoteHide quote "Steven Cheng[MSFT]" <v-sch***@online.microsoft.com> wrote in message news:6t7turZQFHA.3376@TK2MSFTNGXA02.phx.gbl... > Hi Praveen, > > After some further checking , I'm thinking the problem is likely > environment specific or project specific. Based on my local test, (a > control with another dependency), I didn't get the assembly not load > error. > I've tested using strong-named or not strong-named control assembly. As I > also mentioned in another thread, if possible, you can generate a > simplified version of your problem control and let me do some tests on my > local side. > > Looking forward to your response. Thanks, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > > Oh, I see what you're saying. VS.NET adds the incorrect version in the directive?
Well, that's unfortunate. I rarely use the designer in VS.NET. Given these sorts of quirks from VS.NET, it's good to know how to do these things manually. -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > Brock, > > Thanks for the reply. But, like I mentioned I do not want to add the > reference manually, I want my custom control to INSERT this > AUTOMATICALLY into the aspx file in which it was added, if possible. > > Thanks > -Praveen |
|||||||||||||||||||||||