On our BuildServer we are getting a following error:
Result:Load Failure
System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> nCrunch.Common.UserException: Errors occurred while trying to load the project file:
The "GetRestoreProjectStyleTask" task could not be instantiated from the assembly "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'NuGet.Build.Tasks.GetRestoreProjectStyleTask' to type 'Microsoft.Build.Framework.ITask'.
The "GetRestoreProjectStyleTask" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
at nCrunch.Compiler.ComponentAnalysisContext.()
at nCrunch.Compiler.ComponentAnalysisContext.AnalyseComponentBuild()
at nCrunch.Compiler.RemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.(CallMethodMessage )
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
at nCrunch.TaskRunner.Ipc.RemoteInstance.(Byte[] )
at nCrunch.TaskRunner.Ipc.RemoteInstance.Invoke(IMessage msg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at nCrunch.Compiler.IRemoteBuildRunner.AnalyseComponentBuild(ComponentLoadParameters parameters)
at nCrunch.Core.BuildManagement.BuildProcessLauncher..(IRemoteBuildRunner )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , FilePath , String , ExternalProcess )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.(Action`1 , EffectiveProcessorArchitecture , GridClientId , BuildSystemParameters , IList`1 , Nullable`1 , GridAddress )
at nCrunch.Core.BuildManagement.BuildProcessLauncher.AnalyseComponentBuildInExternalProcess(ComponentLoadParameters parameters, IList`1 customEnvironmentVariables)
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.(EffectiveProcessorArchitecture , String )
at nCrunch.Client.ComponentLoader.SnapshotComponentLoader.CreateComponentFromXml(FilePath projectFilePath, ParsedBuildXml projectXml, FilePath solutionFilePath, String[] additionalFilesToIncludeAtSolutionLevel, Boolean isLoadedFromFile, VisualStudioVersion vsVersion, ComponentUniqueName componentName, TaskSettings componentTaskSettings, Exception parseException, String targetFramework)
On my dev machine, if i use the same cli command to start ncrunch and use the same grid server, it works without Problem.
Can you help me please to find out what is going wrong?
The error does not occur every time, often everything works as it should.
I was able to make 2 detailed logs: one with error and one without.
I found that, on run with the error, logs with a message "Added binding redirect for: Microsoft.Build.Framework" are missing
Thanks for sending this through. Could you confirm for me if you have the NCrunch 'Build process CPU architecture' setting set to a consistent value for all the projects in your solution, and if not, does setting this to the same thing for all projects resolve the issue?
Thanks for confirming this. I'm wondering if you can check the following for me:
- Is there any difference if you specify the version of Visual Studio to be used by the console tool through the /VS parameter?
- Which versions of Visual Studio or the MSBuild tools do you have installed on your build server?
- Can you check if there are any directories inside "C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem" while your build isn't running? If so, does clearing these out make any difference?
Remco wrote:Thanks for confirming this. I'm wondering if you can check the following for me:
- Is there any difference if you specify the version of Visual Studio to be used by the console tool through the /VS parameter?
No.
Remco wrote:- Which versions of Visual Studio or the MSBuild tools do you have installed on your build server?
VS Professional 2019 16.7.7
Remco wrote:- Can you check if there are any directories inside "C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem" while your build isn't running?
Yes, There are some directories.
Remco wrote: If so, does clearing these out make any difference?
It helps. I did 10 runs and all were successful.
PS. After each run was a new directory under C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem created.
spolonski wrote:Sorry, i can't reproduce it anymore. I have not saved files from the directory C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem
Fair enough :)
The fix included in this build makes NCrunch more resilient to corruption of this particular directory. I think this problem was caused by failed cleanup (probably due to file locks) which left the BuildSystem directories in an invalid state. Because they hung around, it was just a matter of time until a new process spawned with the same ID as the broken directory and assumed ownership of it.
NCrunch will now fix up the directory if it exists in an unexpected state. So in theory, under the new build you should never see this problem again.
Weird problem happened again today. Something with a message "Test not run". Because of weirdness my first test was to clear the directory C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem. After that, the error disappeared.
I just wanted to let you know that the fix doesn't (always) work. We clean now the directory regularly.
spolonski wrote:
Weird problem happened again today. Something with a message "Test not run". Because of weirdness my first test was to clear the directory C:\Users\f-tfsbuild\AppData\Local\NCrunch\BuildSystem. After that, the error disappeared.
I just wanted to let you know that the fix doesn't (always) work. We clean now the directory regularly.
Thanks for letting me know.
There are a LOT of things that can cause the tests not run error. I think most likely this was caused by a different, intermittent problem. There are things in your own code and environment that can also cause this problem (i.e. out of memory exceptions, etc). The problem described earlier in this thread was a fairly open and shut case. I don't think that clearing the BuildSystem directory will have any affect on this problem.