Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
I'm getting "LinkAssemblies" task failed unexpectedly with error output:
Xamarin.Android.XamarinAndroidException: error XA2006:
Reference to metadata item
(defined in 'System.Buffers, Version=22.214.171.124, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51')
from 'System.Buffers, Version=126.96.36.199, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' could not be resolved. -
--> Mono.Cecil.ResolutionException: Failed to resolve System.Void System.Diagnostics.Tracing.EventSource::WriteEventCore(System.Int32,System.Int32,System.Diagnostics.Tracing.EventSource/EventData*)
at Mono.Linker.Steps.MarkStep.MarkMethod(MethodReference reference)
at Mono.Linker.Steps.MarkStep.MarkInstruction(Instruction instruction)
at Mono.Linker.Steps.MarkStep.MarkMethodBody(MethodBody body)
at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
--- End of inner exception stack trace ---
at Xamarin.Android.Diagnostic.Error(Int32 code, Exception innerException, String message, Object args)
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() Orderion.App.Droid C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1616 Build
Thanks for the report!
I believe this has been resolved in the latest Beta versions by https://github.com/mono/mono/commit/3c3ef17376f5b4e71ac024210672e2d0484f3419.
I made a first attempt at trying to hit this error myself on the current Beta version of Xamarin.Android (188.8.131.52): I added the System.Buffers 4.0.0 NuGet package to a template Android application, added a couple uses of `ArrayPool` to the application, and tried building the .apk with the managed linker set to either "all" or "SDK only". I wasn't able to hit the error in those conditions.
I also quickly checked that `void System.Diagnostics.Tracing.EventSource.WriteEventCore(int, int, EventSource.EventData* data)` did exist in the Xamarin.Android version of `mscorlib.dll`, and it was present as expected.
If those results don't match up with your testing, then to help the Xamarin team address this issue as efficiently as possible, please provide additional information, such as:
- If possible, please attach a small, self-contained test case that reproduces the bug with as little code as possible.
- Briefly describe the steps you followed to encounter the error.
- Include the full log context of the error messages you are seeing. This looks like a build time error, so please attach back the complete diagnostic MSBuild output .
- Describe the environment where the bug was encountered, including the operating system and versions of Xamarin and any dependencies.
See https://kb.xamarin.com/customer/en/portal/articles/1910343 for additional details on what to include. Thanks in advance!
I am also getting this linker error when I try to build in RELEASE mode only.
By the way, this error occurs only when linker setting is set to SDK assemblies only.
When it's set to SDK and user assemblies, project builds successfully.
You said it's been fixed in the latest beta versions, does that mean I have to download the latest beta xamarin to resolve this error?
Can you tell me exactly what should I do to workaround this bug?
The error is caused by a method declaration that is missing from Xamarin.Android's version of `mscorlib`. The linker is looking for `System.Diagnostics.Tracing.EventSource.WriteEventCore()`, but that method declaration did not exist in Mono (and Xamarin.Android) until it was added in .
The linker  is looking for that method as it walks through the tree of all the types and methods it needs to preserve. The "System.Buffers" NuGet package includes a code path that uses `System.Diagnostics.Tracing.EventSource.WriteEventCore()`. When you set the linker to "SDK and user assemblies", the "System.Buffers" NuGet package itself becomes eligible for linking. So what I suspect is happening is that the code path that uses `WriteEventCore()` in "System.Buffers" is being removed by the linker. Once that code path is gone, the linker no longer needs to worry about walking down _into_ `WriteEventCore()` (to preserve the types used by _that_ method), so the fact that `WriteEventCore()` doesn't exist in Xamarin.Android is no longer a problem.
Updating to the Beta version is indeed the most straightforward approach to resolve the issue. The Beta version of `mscorlib` now includes the `WriteEventCore()` method declaration. But based on your observations, setting the linker to "SDK and user assemblies" seems like it would be a valid approach for you too (at least, as long as you don't change your app's usage of "System.Buffers" in such a way that it starts hitting the `WriteEventCore()` code path). Of course, you might wish to add most of your assemblies to the linker's "skip" field so that you don't have to worry about making sure _all_ of them are safe for the linker. You could probably skip all of your external libraries and user assemblies _except_ for "System.Buffers" and that would still be sufficient to avoid the error.
I can confirm that this issue is resolved by installing latest beta 184.108.40.206.