Steps to reproduce
Attempt to build the attached test case in the Release configuration:
msbuild -restore -p:Configuration=Release
Test case: InterfacesRealmWeaver.zip
(This test case uses the Fody IL manipulation library via Realm. Hitting the issue requires a fairly particular usage of generic types in combination with the Realm weaver. The issue was originally found by the developers of a full app: https://github.com/toggl/mobileapp)
Expected behavior
With Xamarin.Android 9.3, the build completes successfully.
Actual behavior
The LinkAssemblies step fails:
(_LinkAssembliesShrink target) ->
error MSB4018: The "LinkAssemblies" task failed unexpectedly.
error MSB4018: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
error MSB4018: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
error MSB4018: at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
error MSB4018: at System.Collections.Generic.List`1.Enumerator.MoveNext()
error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessMarkedTypesWithInterfaces()
error MSB4018: at Mono.Linker.Steps.MarkStep.ProcessPrimaryQueue()
error MSB4018: at Mono.Linker.Steps.MarkStep.Process()
error MSB4018: at MonoDroid.Tuner.MonoDroidMarkStep.Process(LinkContext context)
error MSB4018: at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
error MSB4018: at Mono.Linker.Pipeline.Process(LinkContext context)
error MSB4018: at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
error MSB4018: at Xamarin.Android.Tasks.LinkAssemblies.Execute()
error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
Partial workaround
Add ClassLibrary1 to the Skip linking assemblies field in the Android Options sections of the Visual Studio project property pages for the Android app project. This would allow an existing application to continue linking most of the user assemblies while skipping specific problematic assemblies that by chance hit this combination of factors involving generic types with the Realm weaver.
Version information
Expected behavior:
Xamarin.Android SDK 9.3.0.23 (d16-1/ebd7bda)
Actual behavior:
Xamarin.Android SDK 9.4.0.51 (d16-2/9fa7775)
Xamarin.Android SDK 9.5.0.27 (d16-3/16c4494)