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:
authorMatt Ward <matt.ward@xamarin.com>2017-05-10 16:39:38 +0300
committerMatt Ward <matt.ward@xamarin.com>2017-05-10 16:39:38 +0300
commit11e72fbd36012fc3e2ecc591a508935657c3a000 (patch)
treeb16219c3428a73a450140ccb537f9b3e045a9b14 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates
parentf4aa429ec75029dc5923ec2de79c96ed53da7be4 (diff)
[Ide] Fix TypeInitializationException if no templates available
The new templating engine used for .NET Core projects throws an exception if an attempt is made to save the templating cache when there are no templates available. This then causes the MonoDevelop.Ide addin to not load due a TypeInitializationException being thrown when creating the MicrosoftTemplateEngineProjectTemplatingProvider. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'MonoDevelop.Ide.Templates.MicrosoftTemplateEngineProjectTemplatingProvider' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object at Microsoft.TemplateEngine.Edge.Settings.SettingsLoader.Save (Microsoft.TemplateEngine.Edge.Settings.TemplateCache cacheToSave) in at Microsoft.TemplateEngine.Edge.Settings.SettingsLoader.Save () at MonoDevelop.Ide.Templates.MicrosoftTemplateEngineProjectTemplatingProvider.UpdateCache () in main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs:85 at MonoDevelop.Ide.Templates.MicrosoftTemplateEngineProjectTemplatingProvider..cctor () in main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs:66 Now if there are no templates then no attempt is made to update the templating cache which avoids this exception and prevents extra work being done when it is not needed. If a template becomes available the cache will be updated.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs7
1 files changed, 7 insertions, 0 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
index e34ac65025..f5f75c32e6 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineProjectTemplatingProvider.cs
@@ -73,6 +73,13 @@ namespace MonoDevelop.Ide.Templates
{
if (dontUpdateCache)//Avoid updating cache while scan paths are added during registration
return;
+
+ // Prevent a TypeInitializationException in when calling SettingsLoader.Save when no templates
+ // are available, which throws an exception, by returning here. This prevents the MonoDevelop.Ide addin
+ // from loading. In practice this should not happen unless the .NET Core addin is disabled.
+ if (!TemplatesNodes.Any ())
+ return;
+
var paths = new Paths (environmentSettings);
//TODO: Uncomment this IF, but also add logic to invalidate/check if new templates were added from newly installed AddOns...