locked
Loading XAML with custom dll references RRS feed

  • Question

  • Hi,

    I am trying to load a XAML file (Window instance) using XamlReader as follows:

    FileStream xamlFile = new FileStream("DynamicWindow.xaml", FileMode.Open, FileAccess.Read);  
     
    Window win = XamlReader.Load(xamlFile) as Window;  
     
    win.Show(); 

    ....and the runtime has trouble resolving the custom dll references in the above xaml file. For example, I have this assembly referenced in this xaml file:

    <Window  
     xmlns:libcontrols="clr-namespace:MyNameSpace;assembly=MyAssembly"

    I am sure the above will not work because the MyAssembly is not referenced in my original app. But, I am not sure how to correctly refer to this assembly which is in GAC.

    Any help would be appreciated.

    Thanks.
    Praveen
    Monday, June 30, 2008 3:51 PM

Answers

  • Hi Praveen,
        What you need to do in this scenario is to fully qualify your namespace reference.  I tried this experimentally with an Assembly named (and with namespace) Gaxperiment, and to reference the control I needed to give the name as it exists in the GAC, like so:


    xmlns:myGacAsm="clr-namespace:Gaxperiment;assembly=Gaxperiment,Version=1.0.0.0,Culture=neutral,PublicKeyToken=1a3023e02950a0c1,processorArchitecture=MSIL" 

    ... of course the assembly needs to be strong-name signed as well.  I got the above string (the part after "assembly=") by calling gacutil /l <assembly name>.

    Hope this helps,
    Matt
    SDET : Deployment/Hosting
    Monday, June 30, 2008 6:37 PM

All replies

  • Hi Praveen,
        What you need to do in this scenario is to fully qualify your namespace reference.  I tried this experimentally with an Assembly named (and with namespace) Gaxperiment, and to reference the control I needed to give the name as it exists in the GAC, like so:


    xmlns:myGacAsm="clr-namespace:Gaxperiment;assembly=Gaxperiment,Version=1.0.0.0,Culture=neutral,PublicKeyToken=1a3023e02950a0c1,processorArchitecture=MSIL" 

    ... of course the assembly needs to be strong-name signed as well.  I got the above string (the part after "assembly=") by calling gacutil /l <assembly name>.

    Hope this helps,
    Matt
    SDET : Deployment/Hosting
    Monday, June 30, 2008 6:37 PM
  • Matt,

    Thanks, that worked. I was pretty close actually. I had a "space" between version and culture in the fully qualified name reference and that was causing errors.

    For those of you who can see the above code in IE, here it is again:

    xmlns:myGacAsm="clr-namespace:Gaxperiment;assembly=Gaxperiment,Version=1.0.0.0,Culture=neutral,PublicKeyToken=1a3023e02950a0c1,processorArchitecture=MSIL" 


    Praveen
    Monday, June 30, 2008 6:50 PM
  • Matt,

    Another big issue is that I am not able to load such files (with fully qualified name references) as is (outside the context of any project) in VS.Net or Blend for designing.

    You see we have several such files that our designers work with and it would be much easier for them/us to work with just files rather than projects (with all the custom dll references).

    Is that something that's possible? May be we can register our custom dlls somewhere so that VS.Net and Blend would pick them up when files are loaded (outside the context of projects).

    Thanks
    Praveen
    Monday, June 30, 2008 7:06 PM
  • Hi,
        I'm not sure why, but I can't add controls to my designer from non-WPF assemblies in the GAC.  Most likely this is a security issue mitigation, since some of the control's code is actually executed when rendering it to the screen... but there could be a trick needed to get that to work.  I will investigate and create a tracking bug if it turns out to be the cause.

        The easiest way to make this work though is to just select "Choose Items" on the VS toolbox, select "Browse" and point the file dialog at your custom .DLL.  Once this is done, the control(s) from that assembly will appear on the list for you to check/uncheck, and the checked choices will appear in the toolbox.    I dont have blend installed on a machine at the moment but I believe the steps are conceptually similar.

    Hope this helps,
    Matt
    SDET : Deployment/Hosting
    Monday, June 30, 2008 10:51 PM