Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

Late loading/binding? RSS

2 replies

Last post Jul 07, 2007 01:33 AM by bobk333

(0)
  • jonesed

    jonesed

    0 Points

    3 Posts

    Late loading/binding?

    May 21, 2007 02:29 AM | LINK

    Is it possible to not load specific class libraries (dlls) from a webserver until requested to do so programmatically?

    If so, how might this be accomplished? 


    Thanks for your time!

     -Kevin

  • jcansdale

    jcansdale

    Member

    14 Points

    3 Posts

    Re: Late loading/binding?

    May 21, 2007 02:53 PM | LINK

    Hi Kevin,

    You can use Assembly.Load(...) and Reflection just like with the full .NET CLR. However when using Assembly.Load(...) in Silverlight you must qualify the assembly name with a version number. For example:

    Assembly.Load("ClassLibrary1, Version=1.0.0.0")
    or
    Type.GetType("ClassLibrary1.Class1, ClassLibrary1, Version=1.0.0.0")

    Also you can only call public methods with Reflection in Silverlight.

    You may find the following useful when experimenting with what you can and can't do in Silvelight:
    http://weblogs.asp.net/nunitaddin/archive/2007/05/16/test-with-silverlight-coreclr.aspx

    Cheers,
    Jamie.

    --
    http://www.testdriven.net
    http://weblogs.asp.net/nunitaddn

     

    agclr CLR

  • bobk333

    bobk333

    Member

    4 Points

    2 Posts

    Re: Late loading/binding?

    Jul 07, 2007 01:33 AM | LINK

    Jamie,

    Thanks for this post. I got your example to work using IE but when I try it with Firefox it throws a System.IO.FileNotFoundException.

    I did some research and it looks like the Firefox cache is structured differently than IE's because IE's is just a folder containing the cached files whereas Firefox's cache has the cached files embedded in other non-recognizable file names. So I'm assuming that the Assembly.Load() function is actually looking at the client's local file structure trying to find the file [assemblyName].dll. It can find it in IE but not in Firefox.

    Therefore it seems to me that the only way this can be accomplished across browsers is to download the .dll and .xaml files separately and then call XamlReader.Load() on the downloaded .xaml file. Then somehow Silverlight seems to find the associated .dll both in IE and Firefox. I haven't tested it in Safari but I'm assuming it works fine.

    The only downside to this approach is that you have to download two files; I was hoping to be able to embed the .xaml file in the .dll and then call XamlReader.Load() from a static method within the .dll, which would be nice because you only need one download. However, I could see that depending on the application, it may be beneficial to download the .xaml and .dll files separately if the .xaml files are huge.

    Please let me know if there's a better way of accomplishing this goal.

    Thanks,

    Bob