locked
Blend 3 can't find dynamically loaded assemblies RRS feed

  • Question

  • I am working on a WPF application which dynamically loads some of its assemblies at run time in the following manner:

    System.Type.GetType("assemblyname,classname");

    The assemblies being loaded are all in the project references (and therefore in the ...\bin\debug folder used by VS 2008), and Blend 2 opens the application's MainWindow.xaml without problems when the solution is opened.  Also, the application runs fine stand-alone or when debugging in VS 2008. 

    In Blend 3, however, the dynamically loaded assemblies are not found, so I get the following Exception when Blend 3 tries to open MainWindow.xaml:

      ApplicationException: Can't find an implementation for assemblyname class "classname ". 

    MainWindow.xaml opens fine in Blend 3 if I use the work-around of manually copying the dynamically loaded assemblies to the Blend 3 install folder, but I'd like to get a more workable solution to this problem.  Is this a bug in Blend 3, since Blend 2 doesn't have a problem?  If this is not a bug, is there some other way to tell Blend 3 where to look for these assemblies?

    Update :

    Some further details on this problem

    - Blend 2 with no service pack (version 2.0.1523) has no problem
    - My colleague DOES see this problem running Blend 2 SP1 (version 2.1.1760)
    - The assembly is loaded in code for a user control, not directly in the main window, so the user control is instantiated by Blend to show MainWindow.xaml, which is why the code runs in just opening MainWindow.xaml in Blend
    • Edited by DugCo Friday, August 21, 2009 9:58 PM typo
    Friday, August 21, 2009 7:43 PM

Answers

  • We think that you can do few things to avoid this exception in Blend. These are not ideal workarounds but alternatives good enough to get you going.

     

    1.       If feasible, we suggest avoiding the process of dynamic initialization. You should create UserControl instance directly on your design surface.

     

    2.       You can also  use DesignerProperties.IsInDesignModeProperty.DefaultMetadata.DefaultValue boolean value in System.ComponentModel to avoid execution of your code when running inside Blend. Check Unni’s reply on this http://www.eggheadcafe.com/conversation.aspx?messageid=30312314&threadid=30312309 for more details. This will not be the ideal design time experience but you can continue working on other components on the design surface.

     

    3.       You can use signed assemblies and then everything should work as expected. The process of signing assemblies is pretty simple, please check this link if you need more assistance with signing of assemblies in Visual Studio http://msdn.microsoft.com/en-us/library/ms247123(VS.80).aspx.  You need to sign both assemblies AssemblyLoaded and DynamicallLoadedAssembly. Also you need to remove existing references for these dlls from MainWindow project and add them correctly, this is required so that we have complete strong name in the project references and finally Type.GetType should use full name for the assembly


    Ex:  Type type = Type.GetType("DynamicallyLoadedAssembly.Processor,DynamicallyLoadedAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c90222784c7f601c");

     

     




     

    • Proposed as answer by navits - MSFT Tuesday, August 25, 2009 6:44 PM
    • Marked as answer by DugCo Tuesday, August 25, 2009 7:56 PM
    Tuesday, August 25, 2009 6:44 PM

All replies

  • Hi Dug,
                Will it be possible for you to share your project or a sample to repro this problem? You can send the project directly to me at navits@microsoft.com and we will be happy to take a look at it.

    Thanks,
    Navit Saxena
    Friday, August 21, 2009 7:56 PM
  • Hi Doug,
                    On Investigation we found that this is happening because of a bug in Blend related to unsigned assemblies which was introduced in Blend V2 SP1. Unfortunately we don’t have a work around for this and you might need to wait for a fix. I apologize for inconvenience and thank you for sending a sample project and reporting this issue.

    Monday, August 24, 2009 8:31 PM
  • Does this mean another possible work-around is to sign the assemblies?  I tried this and I still get the same error when Blend tries to show the user control that dynamically loads assemblies.  Just to be sure, I signed all the assemblies in the sample project.
    Tuesday, August 25, 2009 6:05 PM
  • We think that you can do few things to avoid this exception in Blend. These are not ideal workarounds but alternatives good enough to get you going.

     

    1.       If feasible, we suggest avoiding the process of dynamic initialization. You should create UserControl instance directly on your design surface.

     

    2.       You can also  use DesignerProperties.IsInDesignModeProperty.DefaultMetadata.DefaultValue boolean value in System.ComponentModel to avoid execution of your code when running inside Blend. Check Unni’s reply on this http://www.eggheadcafe.com/conversation.aspx?messageid=30312314&threadid=30312309 for more details. This will not be the ideal design time experience but you can continue working on other components on the design surface.

     

    3.       You can use signed assemblies and then everything should work as expected. The process of signing assemblies is pretty simple, please check this link if you need more assistance with signing of assemblies in Visual Studio http://msdn.microsoft.com/en-us/library/ms247123(VS.80).aspx.  You need to sign both assemblies AssemblyLoaded and DynamicallLoadedAssembly. Also you need to remove existing references for these dlls from MainWindow project and add them correctly, this is required so that we have complete strong name in the project references and finally Type.GetType should use full name for the assembly


    Ex:  Type type = Type.GetType("DynamicallyLoadedAssembly.Processor,DynamicallyLoadedAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c90222784c7f601c");

     

     




     

    • Proposed as answer by navits - MSFT Tuesday, August 25, 2009 6:44 PM
    • Marked as answer by DugCo Tuesday, August 25, 2009 7:56 PM
    Tuesday, August 25, 2009 6:44 PM
  • Thanks Navit!  This was a very helpful suggestion!

    I chose option 3.  There were important reasons for dynamically loading the assemblies and using "IsInDesignMode" is sometimes very useful, but in this case it would mean that large portions of the main window would be blank and potentially sized strangely.

    Adding strong names to our assemblies (option 3) is something we thought was a good idea anyway, and now the appearance in Blend is unchanged from runtime.  The part I missed in my first (failed) attempt to implement this was to add the "PublicKeyToken" argument to the string passed to "GetType", but now it's working fine.
    Tuesday, August 25, 2009 7:56 PM