J'ai un énorme problème avec MEF lorsque j'essaie de charger dynamiquement des fichiers XAP. Lorsque je télécharge le fichier catalogue/xap avec l'appel de la méthode dc.DownloadAsync(); Mon Internet Explorer va planter et me montrer le dialogue "IE a cessé de fonctionner". (voir image ci-dessus).Problème avec les fichiers XAP de chargement dynamique avec MEF. IE s'écrase
J'ai suivi plusieurs étapes par des guides d'étapes et je ne peux pas voir ce que je fais mal ou ce que j'ai manqué.
OverView de mon Explorateur de solutions (l'image Se à la fin du poste pour une vue plus détaillée):
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();
}
mise en œuvre:
[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 chargement du 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 http://www.freeimagehosting.net/uploads/cf93454c1a.jpg
Mise à jour après LJ réponse: Test2 est une application Silverlight, j'ai howeever enlevé le App.xaml et MainPage.xaml depuis que j'ai entendu dire qu'ils ne sont pas nécessaire. et quand je construis l'application, je reçois en effet deux fichiers .XAP. J'ai fait exactement les mêmes étapes que vous avez décrites ci-dessus et je reçois le même problème.
J'ai également essayé de déboguer un peu plus loin en ajoutant ces lignes de codes:
dc.DownloadCompleted += (s, args) =>
{
int x = 10;
};
dc.DownloadProgressChanged += (s, args) => {
int x = 10;
};
Tout ce que je remarque est que mes points d'arrêt (i ajouté un à chaque événement) ne reçoit pas touché.
Mise à jour: Essayé avec l'opéra, et a obtenu un meilleur message 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)
Vous mentionnez une image de l'erreur, mais je ne vois pas. –
Quand j'ai fait le post pour la première fois j'ai essayé d'inclure des photos mais comme c'est mon premier article, je n'avais pas assez de réputation (?) Pour les poster. Cependant maintenant j'ai tellement maintenant ils sont ajoutés. – Tino