Bug 40945

Summary: NREX when modifying project/solution properties
Product: [Mono] Compilers Reporter: Marek Habersack <grendel>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+monodevelop, mono-bugs+mono
Priority: ---    
Version: 4.5.X   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Marek Habersack 2016-05-06 18:01:44 UTC
XS master/b2b236de795cb33bacfaeb19b00071ee84b5be6d
Mono JIT compiler version 4.5.1 (master/d36d166 Fri  6 May 11:58:33 CEST 2016)
Ubuntu 16.04 64-bit

When any action is taken which changes the project/solution status and requires saving it to disk, the following exception is thrown (reproducible using https://github.com/xamarin/xamarin-android/)

ERROR [2016-05-05 19:09:05Z]: Save failed.
System.InvalidCastException: Invalid cast from 'System.String' to 'MonoDevelop.Core.FilePath'.
  at System.Convert.DefaultToType (System.IConvertible value, System.Type targetType, System.IFormatProvider provider) [0x00281] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/convert.cs:318 
  at System.String.System.IConvertible.ToType (System.Type type, System.IFormatProvider provider) [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/string.cs:3402 
  at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) [0x0025a] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/convert.cs:381 
  at MonoDevelop.Projects.MSBuild.MSBuildPropertyCore.GetValue (System.Type t) [0x00094] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyCore.cs:70 
  at MonoDevelop.Projects.MSBuild.MSBuildPropertyGroup.SetValue (System.String name, System.Object value, System.Object defaultValue, System.Boolean mergeToMainGroup, System.String condition) [0x00025] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroup.cs:346 
  at MonoDevelop.Projects.MSBuild.MSBuildEvaluatedPropertyCollection.MonoDevelop.Projects.IPropertySet.SetValue (System.String name, System.Object value, System.Object defaultValue, System.Boolean mergeToMainGroup, System.String condition) [0x00006] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildPropertyGroupEvaluated.cs:214 
  at MonoDevelop.Projects.ProjectConfiguration.Write (MonoDevelop.Projects.IPropertySet pset) [0x000a0] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConfiguration.cs:105 
  at MonoDevelop.Projects.DotNetProjectConfiguration.Write (MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProjectConfiguration.cs:75 
  at MonoDevelop.Projects.Project.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:2620 
  at MonoDevelop.Projects.DotNetProject.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs:1617 
  at MonoDevelop.Projects.Project+DefaultMSBuildProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet grp) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:3065 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.ProjectExtension.OnWriteConfiguration (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.ProjectConfiguration config, MonoDevelop.Projects.IPropertySet pset) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:125 
  at MonoDevelop.Projects.Project.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00186] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:2548 
  at MonoDevelop.Projects.DotNetProject.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs:1595 
  at MonoDevelop.Projects.Project+DefaultMSBuildProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:3055 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.Projects.SharedAssetsProjects.SharedAssetsProjectMSBuildExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject project) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.SharedAssetsProjects/SharedAssetsProjectMSBuildExtension.cs:65 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.PackageManagement.PackageManagementMSBuildExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00007] in /home/grendel/vc/mono/monodevelop/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/PackageManagementMSBuildExtension.cs:42 
  at MonoDevelop.Projects.ProjectExtension.OnWriteProject (MonoDevelop.Core.ProgressMonitor monitor, MonoDevelop.Projects.MSBuild.MSBuildProject msproject) [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectExtension.cs:118 
  at MonoDevelop.Projects.Project.WriteProject (MonoDevelop.Core.ProgressMonitor monitor) [0x00042] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:2073 
  at MonoDevelop.Projects.Project+<WriteProjectAsync>c__async10+<WriteProjectAsync>c__AnonStorey32.<>m__0 () [0x00000] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:2054 
  at System.Threading.Tasks.Task.InnerInvoke () [0x00012] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2879 
  at System.Threading.Tasks.Task.Execute () [0x00016] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2502 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:447 
  at MonoDevelop.Projects.Project+<WriteProjectAsync>c__async10.MoveNext () [0x000c8] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:2053 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
  at MonoDevelop.Projects.Project+<OnSave>c__async4.MoveNext () [0x00042] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/Project.cs:533 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
  at MonoDevelop.Projects.SolutionItem+<DoSave>c__async3.MoveNext () [0x00067] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs:442 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
  at MonoDevelop.Projects.SolutionItem+<SaveAsync>c__AnonStorey1C+<SaveAsync>c__AnonStorey1D+<SaveAsync>c__async1B.MoveNext () [0x000c0] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SolutionItem.cs:424 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /home/grendel/tmp/build/mono/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
  at MonoDevelop.Ide.ProjectOperations+<SaveAsyncInernal>c__async4.MoveNext () [0x00110] in /home/grendel/vc/mono/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs:414
Comment 1 Lluis Sanchez 2016-05-09 07:50:31 UTC
I'm going to bet that this is a bug in mcs.

It all starts in ProjectConfiguration.cs:105 (https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/ProjectConfiguration.cs#L105), which has this code:

pset.SetValue ("IntermediateOutputPath", IntermediateOutputDirectory, defaultImPath);

pset is IPropertySet
IntermediateOutputDirectory and defaultImPath are FilePath.

The IPropertySet interface has several overloads for SetValue, see https://github.com/mono/monodevelop/blob/master/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/IPropertySet.cs#L51. What the stack trace shows is that Mono is invoking the SetValue overload that takes Object as parameter, instead of the one that takes FilePath, which is a better match in this case. This is what happens with Mono 4.4.0, so it looks like a bug in Mono 4.5.1.
Comment 2 Marek Safar 2016-05-10 15:43:59 UTC
Fixed in master and Mono 4.5