Bug 57923 - Error executing task GenerateJavaStubs: Sequence contains no elements
Summary: Error executing task GenerateJavaStubs: Sequence contains no elements
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2017-07-04 09:50 UTC by tycho
Modified: 2017-10-04 16:47 UTC (History)
2 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description tycho 2017-07-04 09:50:32 UTC
I am randomly (!) getting this exception and would like to know how to debug it:

4>C:\Users\User\Projects\MyProject\MyProject.csproj(890,3): warning MSB4011: "C:\Users\User\Projects\MyProject\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" cannot be imported again. It was already imported at "C:\Users\User\Projects\MyProject\MyProject.csproj (397,3)". This is most likely a build authoring error. This subsequent import will be ignored. 
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018: The "GenerateJavaStubs" task failed unexpectedly.
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018: System.InvalidOperationException: Sequence contains no elements
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at System.Linq.Enumerable.Max(IEnumerable`1 source)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at System.Linq.Enumerable.Max[TSource](IEnumerable`1 source, Func`2 selector)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator.WriteBinaryMapping(Stream o, Dictionary`2 mapping)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator.WriteJavaToManaged(Stream output)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Xamarin.Android.Tasks.GenerateJavaStubs.UpdateWhenChanged(String path, Action`1 generator)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Xamarin.Android.Tasks.GenerateJavaStubs.Run(DirectoryAssemblyResolver res)
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Xamarin.Android.Tasks.GenerateJavaStubs.Execute()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1668,3): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
4>Done executing task "GenerateJavaStubs" -- FAILED.

If we could debug the .targets tasks ourselves, it would save tremendous amounts of pain, as the only things we really get stuck on are those as they contain no interesting info (for us) as to why it happens... And for you to do anything we need a project that has it which we cannot send (it is a *very* large solution with many PCLs and more NDA's than projects under it). 

Is there any way to go about and just get this into a debugger? Or get more info; what is it trying to run a Linq query on? Where can it not find a result/sequence? Why? 

If I randomly clear/restart VS/Xamarin studio (bug appears on Mac OS X and Windows, in both Visual studio 2017 Win, VS 2017 Mac and Xamarin Studio), it suddenly works, only to be broken again next time. No updates, no reasons... Very bad for us.
Comment 1 tycho 2017-07-04 10:39:39 UTC
By the way; this error is thrown in a PCL this time, other times it is thrown straight in the Android project. It is random. 

I notice the double import which is a warning. I removed that; so that warning can now be ignored from the trace, which makes it, for my eye (hopefully not yours) a stacktrace without any information, hence the reason I ask how to debug. 

The other issue I reported is the same; random and inside a build task. If we can debug ourselves we can help to find it and the many people who lose days because of this stuff as well.
Comment 2 dean.ellis 2017-07-05 09:48:57 UTC
Hi

Thanks for the bug report.

Debugging msbuild tasks is difficult if I remember rightly. It usually involves 2 instances of VS and requires that you have the various debug symbols present (I don't think we ship those).

That said :) The source code for Java.Inteop which is where this error is happening is available [1] . Specifically the error you are hitting seems to be happening at [2]. The Dictionary seems to be empty, so the net question is why? 

Given a repo project will be quite difficult and you cannot send the code, I can suggest getting the source code for Java.Interop and building that in debug. You should then be able to replace the files in the "MSBuild/Xamarin/Android" directory with the new ones (in theory). If that works you can then add Console.WriteLine to the various places to spit out additional output. It should help you track down where this issue happening. My guess is its somewhere in [3] but I could be wrong. 

If you can, please attach a full diagnostic output build which contains the error the might help us help you in narrowing down which assemblies are being passed to GenerateJavaStubs.

BTW replacing the assemblies for the build system depends on the IDE you are using. 
For VS2015 and lower the files are in `Program Files (x86)\MSBuild\Xamarin\Android`
For VS2017 They are now in the IDE edition specific location. Which I think is in 
`Program Files (x86)\Microsoft Visual Studio\2017\<edition>\MSBuild\Xamarin\Android`


[1] https://github.com/xamarin/java.interop

[2] https://github.com/xamarin/java.interop/blob/cd2e96be07d4e0a0e0950af556bf85b3fc25d249/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/TypeNameMapGenerator.cs#L177 

[3] https://github.com/xamarin/java.interop/blob/cd2e96be07d4e0a0e0950af556bf85b3fc25d249/src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers/TypeNameMapGenerator.cs#L133
Comment 3 Jon Douglas [MSFT] 2017-10-04 16:47:04 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!

Note You need to log in before you can comment on or make changes to this bug.