Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control?http://forums.asp.net/t/1469710.aspx/1?Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Thu, 17 Sep 2009 08:36:51 -040014697103400902http://forums.asp.net/p/1469710/3400902.aspx/1?Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control? <p>I have a custom server control for asp.net.&nbsp; One of the properties available to it is a generic object.&nbsp; That generic object has custom attributes that are read and used to customize the rendering of the control.<br> <br> At run time, this is no problem, since all I need to do is find all the attributes on the instance that gets passed into the control.<br> <br> However, just as the &quot;DataSource&quot; member of controls can call up a list of object types at design time, I would like to be able to bring up a list of types in the host assembly.&nbsp; There is no need for actual instances, since I'm rendering based on attributes.<br> <br> This is an example property from the host control:<br> <br> <pre class="prettyprint">[Browsable(true)] [TypeConverter(typeof(TheObjectConverter))] public object TheObject { get { return _theObject; } set { SetTheObject(value); } }</pre><br> <br><br>What I want to have happen is to have TheObjectConverter be able to load the assembly of the host page for the control.<br><br>None of the following seem to work<br><pre class="prettyprint">.GetReferencedAssemblies(); .GetExecutingAssembly(); .GetCallingAssembly(); .GetEntryAssembly(); .GetAssembly(); </pre><br> <br> <br> I even a full recursion against .GetReferencedAssemblies(), with no luck.&nbsp; It seems I am unable to load the assembly of the control's host at design time.&nbsp; Is that correct, or is there a way to do this?</p> 2009-09-12T02:46:58-04:003402142http://forums.asp.net/p/1469710/3402142.aspx/1?Re+Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Re: Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control? <p>&nbsp;Hi,<br> What you want to know is&nbsp;the way to <strong>have type information of certain type (as objectconverter) from host page&nbsp;of&nbsp;your custom&nbsp;control</strong>. Is it correct? If so, I think I can help. Please see the following code.<br> </p> <pre class="prettyprint">// you may input objecttypeconverter's typeinfo in argument when you call this. private List&lt;string&gt; GetTargettClassNameList(Type compareType) { List&lt;string&gt; retList = new List&lt;string&gt;(); Assembly crrAssembly = Assembly.GetExecutingAssembly(); Module[] mods = crrAssembly.GetModules(); foreach (Module md in mods) { Type[] typeArray = md.GetTypes(); foreach (Type myType in typeArray) { if (myType.IsSubclassOf(compareType)) { retList.Add(myType.FullName); } } } return retList; }</pre> <P>Above code shows the way to <STRONG>get type info inside current working assemblies</STRONG>. I'm afraind it might meet the point of your question.<BR>If you also want to get <STRONG>type information from assembly to which host application have reference</STRONG>, see the following.<BR></P><pre class="prettyprint">private List&lt;string&gt; GetTargettClassNameListFromReference( Type compareType, IWebApplication argWebApp ) { List&lt;string&gt; retList = new List&lt;string&gt;(); string binFoler = argWebApp.RootProjectItem.PhysicalPath + @"\bin"; DirectoryInfo di = new DirectoryInfo(binFoler); if (di.Exists) { foreach (FileInfo fi in di.GetFiles()) { Assembly dllAssembly = Assembly.LoadFrom(fi.FullName); Module[] dllMods = dllAssembly.GetModules(); foreach (Module md in dllMods) { Type[] typeArray = md.GetTypes(); foreach (Type myType in typeArray) { if ((myType.IsClass) &amp;&amp; (myType.IsPublic) &amp;&amp; (myType.IsSubclassOf(compareType)) { retList.Add(myType.FullName); } } } } } return retList; }</pre> <p>I can't tell it's a normal way or not, however it works. (<strong>Someone please show us a&nbsp;formal way!</strong>).<br> Hope it might help you. Good-luck!<br> <br> </p> 2009-09-13T16:41:09-04:003402458http://forums.asp.net/p/1469710/3402458.aspx/1?Re+Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Re: Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control? <p>Unfortunately, this does not allow me to get the assembly which is currently being designed in Visual Studio designer -- the assembly hosting the control.&nbsp; I think there may simply be no way to do this.<br> </p> 2009-09-13T23:32:52-04:003403940http://forums.asp.net/p/1469710/3403940.aspx/1?Re+Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Re: Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control? <p>Hi, </p> <p>I have uploaded sample web program which, I hope, may help you. <br> Please download it from </p> <p><a href="http://www.ad.il24.net/~masa_cmt/Samples/DesignTimeTest01.zip">http://www.ad.il24.net/~masa_cmt/Samples/DesignTimeTest01.zip</a> </p> <p>In this program, I prepared custom server control &quot;<strong>ConverterViewer</strong>&quot; which shows the <strong>list of Converter&nbsp;collected from current working assembly</strong>.<br> When you open test form &quot;<strong>ConverterNameTest.aspx</strong>&quot; in design mode, choose &quot;<strong>Converters</strong>&quot; property in property grid, click reference button, then Windows Dialog Form will pop up.</p> <p>In that modal dialog, you'll find the <strong>list of converters inside current assembly</strong>. (These converters are defined inside inner folder of App_Code&quot;) Inside the lower listbox, those which are already selected as property&nbsp;are shown.</p> <p>The place I collect assembly information is around line 254 of &quot;ConverterInfo.cs&quot; Source file. Method name is &quot;<strong>GetCandidateConverterList</strong>&quot; which is called from EditValue method of custom UITypeEditor.</p> <p>I hope, it may help you solving your problem. Or at least it might give you any kind of progress. If not, please forget it.</p> <p>Good luck.</p> 2009-09-14T15:10:18-04:003410137http://forums.asp.net/p/1469710/3410137.aspx/1?Re+Is+it+possible+for+a+custom+asp+net+control+to+load+types+at+design+time+from+the+assembly+hosting+the+control+Re: Is it possible for a custom asp.net control to load types at design time from the assembly hosting the control? <p>I suppose I should have specified that my controls are compiled in a separate projct (dll library), and are not part of App_Code, which may make a difference.<br> </p> 2009-09-17T08:36:51-04:00