'OmniSharp failure: Can't create task 'GetReferenceNearestTargetFrameworkTask'
I'm using VSCode with C# extension (checked version - it's latest - 1.23.11) and quite happy with it. However, today it suddenly stopped working (no Intellisense or navigation). I've checked logs of OmniSharp and found following error:
Failed to create instance of task "GetReferenceNearestTargetFrameworkTask"
from "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.Build.Tasks.dll".
Task assembly should be built with the same version of assembly Microsoft.Build.Framework,
which is installed on computer, and in host should be set binding redirection for Microsoft.Build.Framework.
Failed to cast type "NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask" to type "Microsoft.Build.Framework.ITask".
That may be not exact text - I got localized messages and translated it
Then I've checked what dependencies has 'NuGet.Build.Tasks.dll' - it has 'Microsoft.Build.Framework, 4.0.0'. I've checked what binding redirections has 'Omnisharp.exe'. 'OmniSharp.exe.config' contains:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0-99.0.0.0" newVersion="15.1.0.0" />
</dependentAssembly>
So, redirection is present.
I've turned on 'Debug' log in 'Omnisharp' to see if it loads correct 'Microsoft.Build.Framework' and yep, it loads correct one.
I even tried to comment out 'GetReferenceNearestTargetFrameworkTask' in 'Microsoft.CSharp.targets' - then it fails with similar, but for another type of task.
Can anyone help me handle it, or give some idea - what to check? The most curious thing is that it worked perfectly yesterday evening, but fails today and I can't find any signs of any updates which can break it.
UPD I managed to overcome the problem - removed Microsoft.Build.Framework
assembly from GAC (it was there with 4.0 version). Still I didn't understand why it was tried at all, while working in OmniSharp.exe
process that has bindingRedirect
set.
Solution 1:[1]
I had this problem again and I'm posting the commands to resolve this for anyone else running this on Linux (spcifically Arch):
ls /usr/lib/mono/gac/ | grep v4 | xargs -I R sudo rm -rf /usr/lib/mono/gac/R
ls /usr/lib/mono/gac/Microsoft.Build.Framework/ | grep "^4.0.0" | xargs -I R sudo rm -rf /usr/lib/mono/gac/Microsoft.Build.Framework/R
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hrvoje Juri? |