Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <lluis@xamarin.com>2019-09-10 11:24:39 +0300
committerGitHub <noreply@github.com>2019-09-10 11:24:39 +0300
commit274d634ce11c9be4dcc0927d81052e8640ddfc9b (patch)
tree6034deb43b3f3ee70a1346cbe8a746fd3999d93b /main/src/core/MonoDevelop.Ide
parent4db86dc22dde7ae01eff1e1ec23b6997a4fdfdbc (diff)
parent248133319250923724c9805185d90021035df34e (diff)
Merge pull request #8561 from mono/mef-startup
[Ide] If MEF is queried before startup handlers are run, throw an exc…
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs13
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs6
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs5
3 files changed, 19 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs
index 0f700ca2b9..ef092bf165 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Composition/CompositionManager.cs
@@ -56,12 +56,23 @@ namespace MonoDevelop.Ide.Composition
new AttributedPartDiscoveryV1 (StandardResolver),
new AttributedPartDiscovery (StandardResolver, true));
+ static Action HandleMefQueriedBeforeCompletion = UninitializedLogWarning;
+
+ static void UninitializedLogWarning ()
+ => LoggingService.LogWarning ("UI thread queried MEF while it was still being built:{0}{1}", Environment.NewLine, Environment.StackTrace);
+
+ static void UninitializedThrowException ()
+ => throw new InvalidOperationException ("MEF queried while it was still being built");
+
+ internal static void ConfigureUninitializedMefHandling (bool throwException)
+ => HandleMefQueriedBeforeCompletion = throwException ? new Action (UninitializedThrowException) : new Action (UninitializedLogWarning);
+
public static CompositionManager Instance {
get {
if (instance == null) {
var task = Runtime.GetService<CompositionManager> ();
if (!task.IsCompleted && Runtime.IsMainThread) {
- LoggingService.LogInfo ("UI thread queried MEF while it was still being built:{0}{1}", Environment.NewLine, Environment.StackTrace);
+ HandleMefQueriedBeforeCompletion ();
}
instance = task.WaitAndGetResult ();
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs
index 85166f9665..b990cdcdf5 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/Ide.cs
@@ -314,6 +314,10 @@ namespace MonoDevelop.Ide
// Startup commands
Counters.InitializationTracker.Trace ("Running Startup Commands");
AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged);
+
+ // Let extensions now access CompositionManager.Instance and start asynchronously composing the catalog
+ CompositionManager.ConfigureUninitializedMefHandling (throwException: false);
+ Runtime.GetService<CompositionManager> ().Ignore ();
}
public static Task EnsureInitializedAsync ()
@@ -423,7 +427,7 @@ namespace MonoDevelop.Ide
LoggingService.LogError ("Type " + args.ExtensionObject.GetType () + " must be a subclass of MonoDevelop.Components.Commands.CommandHandler");
}
} catch (Exception ex) {
- LoggingService.LogError (ex.ToString ());
+ LoggingService.LogError ($"Error while running startup handler {args.ExtensionObject.GetType ()}", ex);
}
});
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs
index 5c9ead2641..b08a9c9516 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/IdeStartup.cs
@@ -76,6 +76,8 @@ namespace MonoDevelop.Ide
int Run (MonoDevelopOptions options)
{
+ CompositionManager.ConfigureUninitializedMefHandling (throwException: true);
+
LoggingService.LogInfo ("Starting {0} {1}", BrandingService.ApplicationLongName, IdeVersionInfo.MonoDevelopVersion);
LoggingService.LogInfo ("Build Information{0}{1}", Environment.NewLine, SystemInformation.GetBuildInformation ());
LoggingService.LogInfo ("Running on {0}", RuntimeVersionInfo.GetRuntimeInfo ());
@@ -437,9 +439,6 @@ namespace MonoDevelop.Ide
static bool OnIdle ()
{
- // Make sure the composition manager started initializing
- Runtime.GetService<CompositionManager> ();
-
// OpenDocuments appears when the app is idle.
if (!hideWelcomePage && !WelcomePage.WelcomePageService.HasWindowImplementation) {
IdeApp.Workbench.Present ();