简体   繁体   中英

Silverlight Error Loading dll at Runtime

I've got a silverlight application that loads a dll file located within the ClientBin folder at run time via a relative Uri. It works great on my local machine, but when deployed on a server here, it seems to constantly fail while trying to load the file:

private void OnAssemblyOpened(object sender, OpenReadCompletedEventArgs e)
{  
    AssemblyPart asmbPart = new AssemblyPart();

    MessageBox.Show(e.ToString());
    Assembly asmb = asmbPart.Load(e.Result) // this line causes the exception
    ...
}

Of course silverlight doesn't give me a useful error - just the usual NotFound nonsense. Is there a step I've missed in deploying this? Permissions or something? The dll file is definitely in the ClientBin folder btw - I've checked that! :)

Another option would be to compress the dll into a zip file, then download the zip file. That way you need not play with the server config.

How to download and unpack a file from a Zip file is given in this answer .

Code in essence would look like this:-

AssemblyPart asmbPart = new AssemblyPart();

var zipRes = new StreamResourceInfo(args.Result, null)
var assemRes = Application.GetResourceStream(zipRes, new Uri("YourAssembly.dll", UriKind.Relative));

Assembly asmb = asmbPart.Load(assemRes.Stream)

Try to use absolute path for deployed application and give your url + path-to-clietbin as path.
You may got error because of invalid path on server machine(if you didn't change it and it's still path of your local machine).

Problem was that I'm running IIS6 and dll's cannot be served out without switching execute permissions on the site to None (which obviously stops the Silverlight app from running) so I was legitimately getting a 404 - who'd have thought!!

I created a virtual directory for my scripts at the top level of my site and stuck the dll in there, switched the execute permissions for the virtual to None, updated the uri to ../scripts/ControlLibraries.dll and job's a goodun!

实际上,只需将应用程序的执行权限更改为仅脚本,而不是脚本和可执行文件,就可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM