У меня огромная проблема с MEF, когда я пытаюсь динамически загружать файлы XAP.Когда я загружаю каталог / xap файл с вызовом метода dc.DownloadAsync ();Мой Internet Explorer аварийно завершит работу и покажет мне диалоговое окно «IE прекратил работать».(см. изображение, возлюбленный).
Я прошел несколько шагов пошаговыми инструкциями, и я просто не вижу, что я делаю неправильно или что я пропустил.
Просмотр моего обозревателя решений (см. Изображение в конце публикации для более детального просмотра):
Решение 'AppStation'
- AppStation.Common
- AppStation.GUI
- Test2
Интерфейс:
public interface IApp
{
string Name { get; }
string Description { get; }
UserControl GetUserInterface();
}
Реализация:
[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:
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());
}
}
}
}
альтернативный текст http://www.colincochrane.com/image.axd?picture=WindowsLiveWriter/InternetExplorer8Beta1FirstImpressions_117C3/ie8-2_thumb.jpg
альтернативный текст http://www.freeimagehosting.net/uploads/cf93454c1a.jpg
Обновление после ответа ЖЖ: Test2 - приложение Silverlight, однако я удалил App.xaml и MainPage.xaml, так как я слышал, что они не нужны.и когда я создаю приложение, я действительно получаю два файла .XAP.
Я сделал те же самые шаги, как вы описали выше, и у меня возникает та же проблема.
Я также пыталсяОтладим это немного дальше, добавив следующие строки кода:
dc.DownloadCompleted += (s, args) =>
{
int x = 10;
};
dc.DownloadProgressChanged += (s, args) => {
int x = 10;
};
И все, что я замечаю, - это то, что мои контрольные точки (я добавил один к каждому событию) не получают удар.
Обновление: попробовал с оперой, и получил лучшее сообщение об ожидании:
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)