views:

132

answers:

2

Hello, i am having a huge problem with MEF when i am trying to dynamic load XAP files. When i am download the catalog/xap file with the the method call dc.DownloadAsync(); My Internet explorer will crash and show me the "IE has stopped working" dialog. (see image belove).

I have followed several steps by steps guides and i just cant see what i am doing wrong or what i have missed.

OverView of my Solution Explorer (Se image in the end of the post for a more detailed view):

Solution 'AppStation'

  • 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, Dynamic loading the XAP:

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

alt text

Update after LJ answer: Test2 is a Silverlight Application, i have howeever removed the App.xaml and MainPage.xaml since i heard they were not needed. and when i build the application i do indeed get two .XAP files.

I did the exact same steps as you described above and i am getting the same problem.

I have also tried to debug it a bit further by adding these lines of codes:

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

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

And all i notices is that my breakpoints (i added one to each event) is not getting hit.

Update: Tried with opera, and got a better Expetion message:

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)
+1  A: 

Hi

I managed to create a quick Silverlight business application and get your code running in a few minutes.

Instead of putting code in the MainPage, I put it in the Home Page. I don' think that affects anything - the business app mainpage is just a little crowded.

I did move the CompositionHost.Initialize(catalog); to before the DownloadAsync, although it worked anyway as you had it.

The only thing offhand I can think that you may be doing wrong, is that you have a Silverlight class library for the Test2 project and don't actually have an Silverlight Application Project that generates a the Test2.xap to put in your ClientBin (not expanded in you picture).

Sorry if it doesn't help, but your code is actually working.

I even created a second project application with adding to catalog and downloading and both projects were downloaded.

Hope you have discovered your issue.

LJ

LJ
HelloTest2 is a Silverlight Application, i have however removed the App.xaml and MainPage.xaml since i heard they were not needed. and when i build the application i do indeed get two .XAP files.I did the exact same steps as you described above and i am getting the same problem.I also added a bit of code to debug it more but with no sucess. (Se main post).
Tino
I tried running it in opera and i got a more detailed error message. Se main post for more details.
Tino
A: 

I tried to do all over from step one in the hope that i missed something. How ever i didn't. Same problem even in a new clean project. I then used Opera instead of IE. And it gave me a better error.

I decided to try to run the Main application with opera and it magically worked. This gave me the idea to clear my IE cache and restart the application together with restarting the ASP.NET development Server. And the applikation worked with IE too.

All this without changing one line of code. So all in all i think IE and the cache were the problem all along.

Edit: Now i get the same old error in IE (stopped working) but it is working in opera....

Tino
Why cant i set this answer as my accepted answer now? i have to wait 19 hours?
Tino