Problem with dynamically loading XAP files using MEF. IE is crashing

I have a huge problem with MEF when I try to dynamically load XAP files. When I load the directory / xap file with the dc.DownloadAsync () method call; My Internet Explorer will work and show me that the "IE has stopped working" dialog. (see image belove).

I followed a few steps on the step instructions and I just can't figure out what I'm doing wrong or what I missed.

OverView of my solution explorer (Se image at the end of the post for a more detailed view):

AppStation Solution

  • AppStation.Common
    • IApp.cs
  • AppStation.GUI
    • App.xaml
    • MainPage.xaml
  • Test2
    • HelloMefApp.cs

Interface:

public interface IApp
{
    string Name { get; }
    string Description { get; }

    UserControl GetUserInterface();
}

Implementation:

[Export(typeof(IApp))]
public class HelloMefApp : IApp
{

    public string Name
    {
        get { return "Hello MEF"; }
    }

    public string Description
    {
        get { return "Adds a label with the text 'Hello MEF'"; }
    }

    public UserControl GetUserInterface()
    {
        UserControl uc = new UserControl();

        TextBlock textBlock = new TextBlock();
        textBlock.Text = "Hello MEF";

        uc.Content = textBlock;

        return uc;
    }
}

App.xaml.cs, Application_Startup, XAP dynamic download:

private void Application_Startup(object sender, StartupEventArgs e)
{
    AggregateCatalog catalog = new AggregateCatalog();

    DeploymentCatalog dc = new DeploymentCatalog(new Uri("Test2.xap", UriKind.Relative));
    catalog.Catalogs.Add(dc);
    dc.DownloadAsync(); //This will give the "Internet Explorer has stopped working" crash.

    CompositionHost.Initialize(catalog); 

    this.RootVisual = new MainPage();
}

MainPage:

public partial class MainPage : UserControl, IPartImportsSatisfiedNotification
    {
        [ImportMany(AllowRecomposition = true)]
        public IApp[] Apps { get; set; }

        public MainPage()
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
        }

        public void OnImportsSatisfied()
        {
            if (Apps != null)
            {
                foreach (IApp item in Apps)
                {
                    LayoutRoot.Children.Add(item.GetUserInterface());
                }
            }
        }
    }

alt text http://www.colincochrane.com/image.axd?picture=WindowsLiveWriter/InternetExplorer8Beta1FirstImpressions_117C3/ie8-2_thumb.jpg

alt text http://www.freeimagehosting.net/uploads/cf93454c1a.jpg

LJ: Test2 - Silverlight, howedver, App.xaml MainPage.xaml, , . , .XAP.

, , .

, :

dc.DownloadCompleted += (s, args) =>
{
    int x = 10;
};

dc.DownloadProgressChanged += (s, args) => {
    int x = 10;
};

, , , ( ) .

: Expetion:

Exception has been Thrown by the target of an invocation.       
at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
       at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
    Caused by: Exception has been thrown by the target of an invocation.

       at System.Windows.Navigation.PageResourceContentLoader.EndLoad(IAsyncResult asyncResult)
       at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
+3
2

- Silverlight .

, MainPage, . , - - .

CompositionHost.Initialize(); DownloadAsync, , .

, , , , Silverlight Test2 Silverlight Application Project, Test2.xap ClientBin ( ).

, , .

, .

, .

LJ

+1

, - . . . Opera IE. .

, . IE ASP.NET. IE.

. , IE .

: IE ( ), ....

+1

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


All Articles