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 for Bug 59313 on
Developer Community or GitHub if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
I have followed the guides to replace the Xamarin PCL library with a .Net Standard 2.0 library but if this library uses a method like e.g. Newtonsoft.Json.JsonConvert.DeserializeObject("") from the NuGet package Newtonsoft.Json, the Android project throws the following compilation error:
Severity Code Description Project File Line Suppression State Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Perhaps it doesn't exist in the Mono for Android profile? File name: 'Newtonsoft.Json.dll' at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters) at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel) at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) MyAppName.UI.Xamarin.Android
I am using the latest version of Visual Studio 2017, the latest version of Xamarin and Xamarin.Forms and the latest Windows 10 updates. I am compiling against Android 7.0. Note that this only happens for .Net Standard libraries and I am not sure if this is a .Net Standard bug, they have a new issue that seems to be related to this, see here: https://github.com/dotnet/announcements/issues/31
I should add that the bug even occurs if I downgrade the library to .net standard 1.3 so it seems to be not 2.0 but .net standard specific
Are you able to attach a minimized test case which demonstrates this issue? I want to ensure that any attempts to reproduce and solve the issue are true to your use case.
Created attachment 24640 [details]
I've got the same issue, here's the simple test project attached.
As soon as call to JsonConvert.DeserializeObject is removed, everything compiles properly.
Forgot to mention, this issue happens with all .net standard libraries, not just Newtonsoft.Json. Xamarin.iOS seems to handle everything fine in same situation.
Thanks for providing the minimal sample. I'm glad I'm not the only one with this problem. I found that as a temporary workaround, one can install the NuGet package in the Android project itself to get rid of this error.
Yes, I agree, this problem does not seem to be neither specific to Newtonsoft.Json nor to the version of .Net Standard being used in the class library.
I feel like the issue here is the fact that you do not have Newtonsoft.Json included in your Xamarin.Android project. The big distinguishing factor here is that Xamarin.iOS does not have the same issue. It doesn't need a reference in the platform project to resolve.
If I were to guess, it would be an issue with how NuGet resolves the library in the netstandard project when referenced from Xamarin.Android, or it is an issue within Xamarin.Android picking it up. Either way, we can all agree that this is something that can be looked into further. Thus I am setting this bug to CONFIRMED.
Xamarin.Android 7.5/8.0+ supports netstandard 2.0 items as per the following page:
@Jon Douglas: Thanks for confirming the bug.
If I use a NuGet package API in a class library then I expect to only need to add the NuGet package reference to this library and not the Android project as well. This is the behaviour of PCL libraries when being used as Xamarin BCLs, therefore I expect the same for NetStandard libraries. The reason why the workaround of just adding the NuGet package to the Android project as well is a real issue is because having to add all used NuGet packages to the Android projects creates a NuGet dependency/versioning hell (due to the weird dependencies/incompatibilities of all the Android Xamarin NuGet packages it is a tedious trial and error process to find a combination of NuGet packages that work nicely with each other).
P.S. Although the bug applies to any version of the netstandard, you might want to have a look at this issue about netstandard2.0 and NuGet: https://github.com/dotnet/announcements/issues/31
@Jon Douglss, while the iOS app compiles it does not run as it does not include the Newtonsoft.Json.dll in the final app package.
I think both iOS and Android have the same problem, Android's build process exposes it earlier.
We should ask the msbuild team how to go about solving this issue.
This problem seems to affect both Android and iOS so it is now with our MSBuild Team to figure out why the dependencies for libraries are not being picked up.
Since MSBuild is now open source, could you please open an issue on their GitHub repository below so that everyone can follow the discussion please:
Since there does not seem to be much progress here, I opened a bug directly at MSBuild:
*** Bug 60046 has been marked as a duplicate of this bug. ***
I got around this error by adding Newtonsoft.Json 10.0.3 to the Android project. Hope that helps
At least the workaround is there, even if it does get messy... but do we have any update on this one?
Any updates on this?
The workaround of adding Newtonsoft.Json works but I don't want to have that dependency explicitly there since it pull +20 packages due to .netstandard.