Задайте вопросЗадайте вопрос
 

ОтвеченоLoadComponent - Beta2 --> June CTP

  • 12 июля 2006 г. 23:49Derek Ekins Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    In WinFx Beta 2 I was able to do the following.

    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:
    <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:im="clr-namespace:MyNameSpace"
      >
      <ControlTemplate x:Key="MyKey">
        <im:MyCustomControl Width="100"/>
      </ControlTemplate>
    </ResourceDictionary>
    MyNameSpace exists within MyPluginAssembly and has a custom control called MyCustomControl.

    In my application I did this:
    Application.LoadComponent(new Uri(string.Format(@"{0};;;component\MyResources.xaml", formatType.Assembly.FullName), UriKind.Relative));

    I could then cast the result of LoadComponent to a ResourceDictionary and be on my merry way, using the resources as I saw fit.

    Now with the June CTP and the same code I get an error:
    "Cannot find type 'MyNameSpace.MyCustomControl'  The assembly used when compiling might be different than that used when loading and the type is missing."

    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.

    Here is my take on what is happening.
    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.

    Am I onto something here or is this completely off base?
    One thing I do know is that what did work on Beta 2 does not work on June.
    Can someone offer a workaround for this behaviour?

    Thanks for your help.

Ответы

Все ответы