LoadComponent - Beta2 --> June CTPIn WinFx Beta 2 I was able to do the following.<br><br>In a seperate assembly called MyPluginAssembly (that was not referenced by my application) I had a xaml file called MyResources.xaml that looked like this:<br><pre>&lt;ResourceDictionary xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br>  xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br>  xmlns:im=&quot;clr-namespace:MyNameSpace&quot; <br>  &gt;<br>  &lt;ControlTemplate x:Key=&quot;MyKey&quot;&gt;<br>    &lt;im:MyCustomControl Width=&quot;100&quot;/&gt;<br>  &lt;/ControlTemplate&gt;<br>&lt;/ResourceDictionary&gt;<br></pre>MyNameSpace exists within MyPluginAssembly and has a custom control called MyCustomControl.<br><br>In my application I did this:<br>Application.LoadComponent(new Uri(string.Format(@&quot;{0};;;component\MyResources.xaml&quot;, formatType.Assembly.FullName), UriKind.Relative));<br><br>I could then cast the result of LoadComponent to a ResourceDictionary and be on my merry way, using the resources as I saw fit.<br><br>Now with the June CTP and the same code I get an error:<br>&quot;Cannot find type 'MyNameSpace.MyCustomControl'  The assembly used when compiling might be different than that used when loading and the type is missing.&quot;<br><br>I know that it is the correct version and if I reference the assembly in my main application the code runs fine - this isn't acceptable however as it would mean I no longer have a plugin architecture.<br><br>Here is my take on what is happening.<br>Between Beta 2 and June CTP it looks like a change has happened with how references are resolved when using LoadComponent. Note that in my xaml I have not specified the assembly where the custom control should load from (nor can I because the control is in the same project as the xaml and it won't allow an assembly reference to itself). I think that previously it was looking in the assembly where the component was loaded from, and now it is looking in the application assembly and assemblies referenced by the application.<br><br>Am I onto something here or is this completely off base?<br>One thing I do know is that what did work on Beta 2 does not work on June.<br>Can someone offer a workaround for this behaviour?<br><br>Thanks for your help.© 2009 Microsoft Corporation. All rights reserved.Tue, 14 Jul 2009 15:24:30 Z57ac66ff-2bd4-4a67-b261-9e1724ffeb7ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#57ac66ff-2bd4-4a67-b261-9e1724ffeb7ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#57ac66ff-2bd4-4a67-b261-9e1724ffeb7eDerek Ekinshttp://social.msdn.microsoft.com/Profile/en-US/?user=Derek%20EkinsLoadComponent - Beta2 --> June CTPIn WinFx Beta 2 I was able to do the following.<br><br>In a seperate assembly called MyPluginAssembly (that was not referenced by my application) I had a xaml file called MyResources.xaml that looked like this:<br><pre>&lt;ResourceDictionary xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;<br>  xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;<br>  xmlns:im=&quot;clr-namespace:MyNameSpace&quot; <br>  &gt;<br>  &lt;ControlTemplate x:Key=&quot;MyKey&quot;&gt;<br>    &lt;im:MyCustomControl Width=&quot;100&quot;/&gt;<br>  &lt;/ControlTemplate&gt;<br>&lt;/ResourceDictionary&gt;<br></pre>MyNameSpace exists within MyPluginAssembly and has a custom control called MyCustomControl.<br><br>In my application I did this:<br>Application.LoadComponent(new Uri(string.Format(@&quot;{0};;;component\MyResources.xaml&quot;, formatType.Assembly.FullName), UriKind.Relative));<br><br>I could then cast the result of LoadComponent to a ResourceDictionary and be on my merry way, using the resources as I saw fit.<br><br>Now with the June CTP and the same code I get an error:<br>&quot;Cannot find type 'MyNameSpace.MyCustomControl'  The assembly used when compiling might be different than that used when loading and the type is missing.&quot;<br><br>I know that it is the correct version and if I reference the assembly in my main application the code runs fine - this isn't acceptable however as it would mean I no longer have a plugin architecture.<br><br>Here is my take on what is happening.<br>Between Beta 2 and June CTP it looks like a change has happened with how references are resolved when using LoadComponent. Note that in my xaml I have not specified the assembly where the custom control should load from (nor can I because the control is in the same project as the xaml and it won't allow an assembly reference to itself). I think that previously it was looking in the assembly where the component was loaded from, and now it is looking in the application assembly and assemblies referenced by the application.<br><br>Am I onto something here or is this completely off base?<br>One thing I do know is that what did work on Beta 2 does not work on June.<br>Can someone offer a workaround for this behaviour?<br><br>Thanks for your help.Wed, 12 Jul 2006 23:49:38 Z2006-07-24T08:26:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#8638869b-8ed0-41fb-9cad-3d9a595e607dhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#8638869b-8ed0-41fb-9cad-3d9a595e607dDerek Ekinshttp://social.msdn.microsoft.com/Profile/en-US/?user=Derek%20EkinsLoadComponent - Beta2 --> June CTPAny ideas?<br>I still haven't been able to solve this.<br>Fri, 21 Jul 2006 09:40:25 Z2006-07-21T09:40:25Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#300b500b-e674-4ac4-aef9-abd6d9422526http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#300b500b-e674-4ac4-aef9-abd6d9422526Ashish Shetty - MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Ashish%20Shetty%20-%20MSFTLoadComponent - Beta2 --> June CTPCan you try changing the AssemblyVersion attribute value to a static value instead of the default 1.0.0.*, rebuild and see if this problem can be reproduced? Seems like a known bug in June/July CTPs but I want to make sure.Fri, 21 Jul 2006 16:39:22 Z2006-07-24T08:26:58Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#fb427a4d-25e2-4678-9d67-3cea82af0a02http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#fb427a4d-25e2-4678-9d67-3cea82af0a02Derek Ekinshttp://social.msdn.microsoft.com/Profile/en-US/?user=Derek%20EkinsLoadComponent - Beta2 --> June CTPYes this works. Thanks very much!<br>Mon, 24 Jul 2006 08:26:53 Z2006-07-24T08:26:53Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#441f6b8a-9231-4219-9b02-0a24101c8aaehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#441f6b8a-9231-4219-9b02-0a24101c8aaeEugene S.B_http://social.msdn.microsoft.com/Profile/en-US/?user=Eugene%20S.B_LoadComponent - Beta2 --> June CTP<p>This trick is not working when I try to load different assemblies dynamically.</p> <p>For examle:</p> <p>1. I compile assembly with version 1.0.0.0 on the fly with Form1.xaml - and class Form1</p> <p>2. I dynamically load this assembly and successfully load form by</p><font size=2> <p>System.Windows.</font><font color="#008080" size=2>Application</font><font size=2>.LoadComponent(</font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>Uri</font><font size=2>(<font color="#0000ff" size=2></p> <p>string</font><font size=2>.Format(</font><font color="#800000" size=2>&quot;{0};component\\Form1.xaml&quot;</font><font size=2>, aAssemblyFullName)</p> <p></font>, System.</font><font color="#008080" size=2>UriKind</font><font size=2>.RelativeOrAbsolute));</font></p> <p><font size=2>3. I compile another assembly with version 1.0.0.2 on the fly with Form1.xaml - and class Form2</font></p> <p><font size=2>4. Then I load this assembly and got error when I use LoadComponent. (&quot;The assembly used when compiling might be different....&quot;)</font></p> <p><font size=2></font> </p> <p><font size=2>If I don't change class name to Form2 on the step 2 - load will <font size=3>successfull, but code will be used from old assembly (1.0.0.0). I mean xaml file will be from 1.0.0.2 and event handlers will be from 1.0.0.0.</font></p></font>Thu, 27 Jul 2006 07:38:34 Z2006-07-27T07:38:34Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#ae839645-25f7-42ab-a50b-9683e0749a5fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#ae839645-25f7-42ab-a50b-9683e0749a5fRob Relyeahttp://social.msdn.microsoft.com/Profile/en-US/?user=Rob%20RelyeaLoadComponent - Beta2 --> June CTP<p>Eugene-</p> <p>You refer to step 2...but I didn't see any mention of Form2 in step2.  Can you clarify?</p> <p> </p> <p>All-</p> <p>Please see my blog post about this issue: <a title="http://rrelyea.spaces.msn.com/blog/cns!167AD7A5AB58D5FE!497.entry" href="http://rrelyea.spaces.msn.com/blog/cns!167AD7A5AB58D5FE!497.entry">http://rrelyea.spaces.msn.com/blog/cns!167AD7A5AB58D5FE!497.entry</a></p> <p>Thx, Rob Relyea<br>WPF PM</p>Thu, 27 Jul 2006 22:56:54 Z2006-07-27T22:56:54Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#adad8863-26f0-41ab-b972-985976c27d17http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#adad8863-26f0-41ab-b972-985976c27d17Eugene S.B_http://social.msdn.microsoft.com/Profile/en-US/?user=Eugene%20S.B_LoadComponent - Beta2 --> June CTP<p>First scenario:</p> <p>1. Build assembly with strong name, version 1.0.0.0; Form1.xaml; class Form1 with EventHandlers</p> <p>2. Try to load by LoadComponent -&gt; All is fine.</p> <p>3. Build another assembly with strong name, version 1.0.0.2; Form1.xaml (with the same name, but different content); class Form1 with EventHandlers (with the same name, but different content)</p> <p>4. Try to load by LoadComponent: As result I will have:  succeseful load with GUI  layout from assembly version 1.0.0.2, but EventHandlers from assembly version 1.0.0.0</p> <p>Second scenario:</p> <p>1. Build assembly with strong name, version 1.0.0.0; Form1.xaml; class Form1 with EventHandlers</p> <p>2. Try to load by LoadComponent -&gt; All is fine.</p> <p>3. Build another assembly with strong name, version 1.0.0.2; Form1.xaml (with the same name, but different content); class Form2 with EventHandlers</p> <p>4. Try to load by LoadComponent: so I got exception</p> <p>&quot;Error in markup file 'Form1, Version=1.0.0.2, Culture=neutral, PublicKeyToken=421f993a8952c890;component/form1.xaml' : Cannot find type 'XamlExportedObjects.Form2'. The assembly used when compiling might be different than that used when loading and the type is missing.&quot;</p> <p> </p> <p>If I try to load assembly in another AppDomain and Unload it befor loading another assembly - All is fine, but it is very slowly, because all referenced assemblies will be loaded again and again.</p>Fri, 28 Jul 2006 06:47:01 Z2006-07-28T06:47:01Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#e8205c15-75e4-4a33-ab2a-5446ab22fd29http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#e8205c15-75e4-4a33-ab2a-5446ab22fd29Eugene S.B_http://social.msdn.microsoft.com/Profile/en-US/?user=Eugene%20S.B_LoadComponent - Beta2 --> June CTP<p>In the second scenario, step 3 - Form1.xaml linked with class Form2 for event handlers.</p> <p>I can't use another name for xaml file, because this name depends on my buisness logic, I can only change class name (naturally in both xaml file and source file).</p>Fri, 28 Jul 2006 06:52:28 Z2006-07-28T06:52:28Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#639049a1-15a2-463a-a9b8-1387fcd41467http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#639049a1-15a2-463a-a9b8-1387fcd41467Eugene S.B_http://social.msdn.microsoft.com/Profile/en-US/?user=Eugene%20S.B_LoadComponent - Beta2 --> June CTP<p>I guess the problem is in assembly Short name.</p> <p>When I change assembly short name (with the same version 1.0.0.0) - All is fine.</p> <p>It is very strange, because I use assembly strong name, and different version must be treated as different assemblies. I think it is bug.</p>Fri, 28 Jul 2006 07:56:41 Z2006-07-28T07:56:41Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#a495295a-bf73-4765-bddc-8d297bd85986http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#a495295a-bf73-4765-bddc-8d297bd85986Eugene S.B_http://social.msdn.microsoft.com/Profile/en-US/?user=Eugene%20S.B_LoadComponent - Beta2 --> June CTPThis problem with assembly short name is in Beta 2 Feb CTP, I can't check June CTP. May be this bug is already fixed in June CTP.Fri, 28 Jul 2006 11:18:45 Z2006-07-28T11:18:45Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#aefca83a-ae5b-4c8f-9236-46f2031e77e7http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#aefca83a-ae5b-4c8f-9236-46f2031e77e7BucciAtFiservhttp://social.msdn.microsoft.com/Profile/en-US/?user=BucciAtFiservLoadComponent - Beta2 --> June CTP<p align=left><font face=Arial size=2>Hello Eugene,</font></p> <p align=left> </p> <p align=left>I know you dealt with this issue a while ago.  I'm having the same issue with the Visual Studio 2008 RTM release using the 3.0 framework.  Were you able to solve the problem?</p>Wed, 06 Feb 2008 12:50:32 Z2008-02-06T12:50:32Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#8c8b2a0d-b26f-4daa-bfbc-ac14c435538ahttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#8c8b2a0d-b26f-4daa-bfbc-ac14c435538amsdner1http://social.msdn.microsoft.com/Profile/en-US/?user=msdner1LoadComponent - Beta2 --> June CTP hi BucciAtFisery,<br><br>I am running into this problem now. i guess its not just a bug in the beta issue becuase im running vs 2008 rtm release too. did u ever find a solution to the problem? please advice any help is greatly appreciated. thanks in advance. <br><hr size="1" align="left" width="25%">my favorite place on the net is msdn!Wed, 04 Jun 2008 18:33:44 Z2008-06-04T18:33:44Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#b17526cc-79f9-4e2c-960d-147c298b526ahttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#b17526cc-79f9-4e2c-960d-147c298b526amsdner1http://social.msdn.microsoft.com/Profile/en-US/?user=msdner1LoadComponent - Beta2 --> June CTP<p>i just wanted to post my solution just in case someone else ran into this issue again. since i was working in vs 2008 release version the entry in the assembly file was correct- 1.0.0.0. my issue had nothing to do with the assembly file. i had created a custom control for a user control and then placed that user control in another project. all these files were in one solution. i had dded a reference of the custom control to my user control project and then added a reference to the user control on my main project. i assumed that since i had added the reference of the custom control to the user control project that it was hosted on that it would be sufficient. but it wasnt. i kep getting this load error in the main project. so i ended up adding a reference to the custom controls projects to the main projects reference and that did trick.  hope this helps ppl.</p><hr size="1" align="left" width="25%">my favorite place on the net is msdn!Fri, 06 Jun 2008 14:03:21 Z2008-06-06T14:03:21Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#ccbfe24a-3744-41bc-9f38-0b631c54e863http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#ccbfe24a-3744-41bc-9f38-0b631c54e863darioa123http://social.msdn.microsoft.com/Profile/en-US/?user=darioa123LoadComponent - Beta2 --> June CTP thnaks for your help!<br>I got the same problem and solved it with your advice.<hr size="1" align="left" width="25%">darioaTue, 10 Jun 2008 01:24:34 Z2008-06-10T01:24:34Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#9851783e-32b8-44a5-8f00-b3f2b5f299a4http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#9851783e-32b8-44a5-8f00-b3f2b5f299a4Justin Kalweithttp://social.msdn.microsoft.com/Profile/en-US/?user=Justin%20KalweitLoadComponent - Beta2 --> June CTPthanks! I had this problem too, and you solved it.<br> Tue, 10 Jun 2008 23:51:00 Z2008-06-10T23:51:00Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#d9997b0a-6f89-4840-888b-f8a7d06278f2http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#d9997b0a-6f89-4840-888b-f8a7d06278f2Nunyo Biznatchhttp://social.msdn.microsoft.com/Profile/en-US/?user=Nunyo%20BiznatchLoadComponent - Beta2 --> June CTP Thank you so much for your post!  I had the exact same problem: abstracted a user control out of a main project, had the issue, and adding a (seemingly unnecessary) reference to my UserControl project in my main app and it works now.<br><br>I've got an App -&gt; Dialogs -&gt; Controls project set....App depended on Dialogs, Dialogs on Controls....now App &amp; Dialogs both directly reference Controls.<br><br>I can stop pulling my hair out for a while now. :)Thu, 17 Jul 2008 20:57:20 Z2008-07-17T20:57:20Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#dcddf20a-51db-49ff-9e31-19578905eb3ehttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#dcddf20a-51db-49ff-9e31-19578905eb3emsdner1http://social.msdn.microsoft.com/Profile/en-US/?user=msdner1LoadComponent - Beta2 --> June CTP so glad to help :)<hr size="1" align="left" width="25%">my favorite place on the net is msdn!Thu, 31 Jul 2008 18:13:52 Z2008-07-31T18:13:52Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#b4667fb3-282d-4de6-aeff-37093824c87fhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#b4667fb3-282d-4de6-aeff-37093824c87fAtul Guptahttp://social.msdn.microsoft.com/Profile/en-US/?user=Atul%20GuptaLoadComponent - Beta2 --> June CTP check this - <a href="http://infosysblogs.com/microsoft/2008/08/wpf_appdomain_cannot_find_type.html">http://infosysblogs.com/microsoft/2008/08/wpf_appdomain_cannot_find_type.html</a><hr size="1" align="left" width="25%">MVP Client AppThu, 21 Aug 2008 09:03:01 Z2008-08-21T09:03:01Zhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#c018f2bf-910e-4d9d-9a86-0c4e32291befhttp://social.msdn.microsoft.com/Forums/en-US/wpf/thread/57ac66ff-2bd4-4a67-b261-9e1724ffeb7e#c018f2bf-910e-4d9d-9a86-0c4e32291befzy_deutschlandhttp://social.msdn.microsoft.com/Profile/en-US/?user=zy_deutschlandLoadComponent - Beta2 --> June CTPThanks a lot for the suggesition. Wed, 28 Jan 2009 09:00:08 Z2009-01-28T09:00:08Z