Accessing external static resources placed in different assembly and XAP - silverlight

My prism based silveright application is divided into multiple xaps to reduce initial download size and support multi tenant application.
However, I cannot access the resource dictionaries defined in external assembly (i.e. the resource .xaml file is part of an assembly that complies/ is copied into a different xap)
Any suggestions ? because the standard syntax for accessing external resources files does not work

The book Pro Silverlight 2 in VB 2008 (p166) [MacDonald] says "Unfortunately, Silverlight doesn't currently allow you to merge resource dictionaries, which means there is no way to split your application resources into separate files and then merge them into your application (which is possible in WPF)." I don't know if things have changed since then, but I would suggest that is the reason.

Related

How to access form resources in runtime in Windows Forms?

I need to extract some resources from the MyForm.resx file in runtime. In particular, I need to access captions of controls, which are stored inside.
From what I know, resources are embedded into assembly during compilation. Knowing specific form I want access to (let it be MyForm) and specific name of the resource (like lbSth.Text), is there a way to access those resources in runtime?
There are two ways, depending on what is actually needed.
One may use System.Resources.ResourceManager class. Construct it by passing a Type of form or control, which resources you want to access. It automatically resolves satellite assemblies and provides access to resources related to a form. The downside is that it doesn't allow iterating through key/value pairs, only accessing a resource of known key, so you have to know them in advance (for instance, process resx files beforehand)
It turns out, that resources in binary form are kept as embedded resources in the assembly. However, translations are being kept in satellite assemblies. To access those, use eg. Assembly.GetExecutingAssembly().GetSatelliteAssembly(), however keep in mind, that resources in there will have different names. For instance, MyForm.resources in satellite assembly will be named, eg. MyForm.en.resources.
Afterwards, use resolvedAssembly.GetManifestResourceStream() to access embedded resource and then finally System.Resources.ResourceReader class to iterate through resources in that file.

Common DLL referencing throughout Silverlight project

I have a common silverlight project. This project project, among other things, includes constants and static classes.
The silverlight App i have references this common library.
In addition, i have a handful of external modules that are loaded on-demand (via Prism). Each module is its own .Xap file and they too reference the common library.
So now each Xap in my silverlight application has a reference to the Common.dll.
Does this mean the common.dll is loaded every time a xap is loaded, or does it essentially mean only the main App's common.dll is ever loaded?
The ultimate question im getting at is this:
If i make a code change (bug fix) in the common.dll, do i have to release ALL Xap files or just the main App xap?
Thanks.
If you use Assembly Caching in all projects that reference the common dll then you'll just get one copy downloaded as it's own zip file. This way all the different XAP files will reference the same dll. Otherwise common.dll will be included in each XAP file that references.
You'll need to create a common.extmap.xml file for your common.dll which needs to be in the same folder from where the dll is referenced.
By default DLLs are loaded on demand. This means that you can't really guarantee which directory they will load from. This is a common issue among modular applications and one that there isn't a ready prescription for. It depends on requirements, essentially.
Some things you can do:
GAC the Common.dll in the target environment. This will allow you to control the versioning of that DLL centrally.
Release everything every time Common.dll changes (as you mentioned).
We have opted for number 2 (we treat our "Common.dll" as a contract assembly that changes rarely) in order to keep our xcopy deployments intact.
Number 1 might make more sense if you anticipate that code churn on Common.dll will be high or you want to keep your deployment schedules for modules completely autonomous (like if the modules were being developed and deployed by seperate teams with seperate build and source respositories, for example).
Edit: It looks like Silverlight has something to provide an xcopy variant of the GAC approach. ChrisF's answer is probably the way I would go with Silverlight (we do WPF, so that's a bit different). I'll leave this here for posterity.

Loading a new Silverlight application from isolated storage

Is there any way i can load a silverlight application from isolated storage and replace the current application ?
Short answer: no, you cannot do this. You could however store a dll, read and load it via reflection if you are in a trusted out-of-the-browser application.
Anyway I don't believe this to be a very good practice, it's very likely there is a different better way to solve your particular problem.
You can't replace the currently running application from within Silverlight code.
However you could create a single application to act as a shell. You could store assemblies or entire Xaps in isolated storage. Using the AssemblyPart class allows you to load an assembly from this storage, create an instance of an entry type and execute an entry point method.
The big caveat would be that this "stored application" would have to be coded specifically to work within your shell. You would need to provide your ways in particular to allow for "application" level state to be accessed and a means of loading content assets such as images.

Change resource file on the fly

I woulld like to localize my WPF application with resource files. It good technics. But I have requirement to give ability to end user to change some localization information (for example some word traslation). It means change information in the resourse files on the fly (in run time). Is it possible ?
This would involve recompiling the resources on the fly; and reloading them will be quite difficult (as DLLs cannot be unloaded without unloading an AppDomain).
In such a configuration, you're better off using the database to store your translations.

how to include XSD schema files in Silverlight library?

Within a Silverlight library, I need to validate incoming XML against a schema. The schema is composed of 5 interdependent .xsd files; the main file uses "xs:import" to reference all of the others, and there are other references among them.
Assuming that the .xsd files need to be distributed with the library (i.e. not hosted on some well-known external URL), how should I structure my project to include them?
I have found that I can embed them in the library project with build type "Resource" and then load them (individually) using Application.GetResourceStream() and a relative URI with the ";content" flag in it. But if I take this approach, can I validate against the interdependent set of 5 files? What happens when the schema parser tries to resolve the interdependencies?
Or should I embed them with build type "Content" and access the main one with some other sort of URL?
Or???
To summarize: how should I use these 5 .xsd files in my project so that I will be able to validate XML against them?
EDIT: It's not clear whether it's even possible to validate in Silverlight. I spun off a related question.
I cannot say much about Silverlight limitations with respect to validation, but the question itself is more generic - one might want to store .xsd files as resources in a desktop .NET application, for example - so I will answer that part.
You can have full control over resolution of URIs in xs:import by means of XmlSchemaSet.XmlResolver property. Just create your own subclass of XmlResolver, override GetEntity() method, and implement it using GetResourceStream(), or GetManifestResourceStream(), or whichever other way you prefer.

Resources