Silverlight: loading local files using WebClient

The directory structure of my Silverlight project is as follows:

\Bin
- MainModule.xap
- \Images
--- Image1.png
--- Image2.png
- \Modules
--- SubModule.xap

I want to be able to run it through a web server or through Visual Studio directly (for debugging purposes, I want to bypass content loading).

In my boot code for multimedia, I am doing something like the following:

if (runningLocally)
{
    var bitmapImage = new BitmapImage();
    bitmapImage.UriSource = new Uri("Images/Image1.png", UriKind.Relative);
    var image = new Image();
    image.Source = bitmapImage;
}
else
{
    WebClient wc = new WebClient();
    wc.OpenReadCompleted += (s, e) =>
    {
        var bitmapImage = new BitmapImage();
        bitmapImage.SetSource(e.Result);
        var image = new Image();
        image.Source = bitmapImage;
    };
    wc.OpenReadAsync(new Uri("Images/Image1.png", UriKind.Relative));
}

This works for images, but I also have submodules, which are only UserControls body assemblies . Since Silverlight does not have the ability to read the disk, I put up with the fact that I will have to “download” the XAP files that I need if I work locally or not. The problem is that if I run the project locally and try to use WebClientXAP to load, I get an exception:

System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The URI prefix is not recognized.

- (WebClient ), XAP Silverlight , -?

EDIT:

, MEF DeploymentCatalog, , , , .

+3
2

, Silverlight. - , Silverlight Visual Studio, // .

0

( ), WebClient, IsolStorage.

:

// read/write from/to IsolatedStorage
IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForSite.OpenFile
0

Source: https://habr.com/ru/post/1744395/


All Articles