Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OmniSharp.MSBuild.ProjectFile.ProjectFileInfo - Specified cast is not valid. #903

Closed
DustinCampbell opened this issue Jun 30, 2017 · 2 comments · Fixed by #907
Closed

OmniSharp.MSBuild.ProjectFile.ProjectFileInfo - Specified cast is not valid. #903

DustinCampbell opened this issue Jun 30, 2017 · 2 comments · Fixed by #907
Assignees

Comments

@DustinCampbell
Copy link
Contributor

From @igorkovalchuk on June 30, 2017 13:37

Environment data

Debian 9 "Stretch"

$ mono --version
Mono JIT compiler version 5.2.0.179 (tarball Fri Jun 16 15:46:58 UTC 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: sgen (concurrent by default)

VS Code version: 1.13.1

C# Extension version: 1.11.0

Details

I am working with Xamarin.Forms projects in Linux environment, so It is not possible to reproduce the exact configuration easy (it will take a lot of time), so I publish this issue for your information. Maybe you know already the source of this error.

Generally, you may ignore this issue completely, because I am working tightly only with PCL projects and can use the MonoDevelop for the Droid project if it will be necessary,
but maybe this issue also will appear for other users in the similar specific cases/projects further. So it is FYI.

Steps to reproduce

  • build the xamarin-android project on Linux (or try to use the existing jenkins build );
  • create a simple Xamarin.Forms Android project with PCL using the Visual Studio 2017;
  • try to build it on Linux from the command line (it is possible, I may provide detailed info if you will ask, because it needs some tweaks);
  • open the project in Visual Studio Code (it needs some tweaks - I may provide details if you need);
  • VS Code: you may work with PCL project(s), intellisense will work normally;
  • VS Code: but the Droid project will show an error and intellisense will not work in the Droid project;

After the auto-update from C# extension 1.10.0 to version 1.11.0 I've got these error messages:

The ... task could not be instantiated from the assembly...

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... Specified cast is not valid.

Log

The "ResolveSdks" task could not be instantiated from the assembly "/home/my_home_dir/.vscode/extensions/ms-vscode.csharp-1.11.0/bin/omnisharp/msbuild/Xamarin/Android/Xamarin.Android.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. Specified cast is not valid.

The "ResolveSdks" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

Failed to load project file '/wrk/all/one/projects/Sample/Droid/Sample.Droid.csproj'.
/wrk/all/one/projects/Sample/Droid/Sample.Droid.csproj

Here ~/.vscode/extensions/ms-vscode.csharp-1.11.0/bin/omnisharp/msbuild/Xamarin/ is a symbolic link to my xamarin-android build (xamarin-android/bin/Debug/lib/xbuild/Xamarin).

Details:

Xamarin.Android.Build.Tasks.dll - this dll has been build by myself with xamarin-android project.

I've attached the copy of dll, but if you want you may take a similar copy here:
https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/lastSuccessfulBuild/Azure/
(probably my build is very different, because I've built the newer version of the xamarin-android.)

Xamarin.Android.Build.Tasks.zip

Copied from original issue: dotnet/vscode-csharp#1611

@DustinCampbell
Copy link
Contributor Author

Between 1.10 and 1.11 of C# for VS Code, we updated the Mono build used by OmniSharp with a newer version that supports strict assembly loading. My working theory is that this causes to Microsoft.Build.Framework assemblies to be loaded SxS (one by OmniSharp and one in the Task) and that results in an invalid cast exception when OmniSharp uses MSBuild in-proc because exchange types (e.g. ITask) are in different assemblies. We currently lack the right binding redirects in OmniSharp for the MSBuild assemblies we use. If my theory is right, I expect that adding them will fix this problem (assuming there aren't API breaking changes in MSBuild).

@DustinCampbell
Copy link
Contributor Author

Note: My change here won't fix the problem of not locating the Android task in Mono, but it should address the invalid cast exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant