Could not load assembly 'Newtonsoft.Json. Perhaps it doesn't exist in the Mono for Android profile? - xamarin

The whole exception message below:
Exception while loading assemblies: System.IO.FileNotFoundException:
Could not load assembly 'Newtonsoft.Json, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Perhaps it doesn't
exist in the Mono for Android profile?
I have changed my PCL library to .Net standard 1.6 and i can run library and IOS project successfully. But my android project gave me the above error. If i add the Newtonsoft.Json package to it it gives me different error.
error: package com.squareup.okhttp does not exist
com.squareup.okhttp.Callback
I am stuck with these errors.

This error happens at compile-time when you have the Newtonsoft.Json NuGet Package installed in the .NET Standard project and do not have it installed in the Android project.
To fix it, add the same version of the Newtonsoft.Json NuGet Package to the Android project as well as the .NET Standard project.

Related

Xamarin Forms App Fails to Deploy to Android After Adding AndroidX Migration Packages, error MSB4018 Xamarin.Android.Support.v7.AppCompat.dll

I recently added the AndroidX migration nugget packages to my Xamarin.Android project, within my Xamarin.Forms solution. I followed the following links for migrating to AndroidX:
Introduction to AndroidX for Xamarin
Link to AndroidX NuGet Packages used in the project
I had to add the AndroidX migration packages one-by-one to match the Android.Support libraries and rebuild the project till there are no more build errors. However, when I try to deploy the app to my Android device/emulator I get the following error:
k/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2283,3): error MSB4018: The "GenerateJavaStubs" task failed unexpectedly.
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2283,3): error MSB4018: System.IO.FileNotFoundException: Could not load assembly 'Xamarin.Android.Support.v7.AppCompat, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2283,3): error MSB4018: File name: 'Xamarin.Android.Support.v7.AppCompat.dll'
Please also refer to the following link for the detailed build output from Visual Studio:
App's build output from Visual Studio
Any suggestions?

"Can not resolve reference: `System.Memory`" or "Could not find `System.Memory`" after update to Visual Studio 2017 version 15.8 Preview

In case it might help anyone else, I'll ask and answer this little question about an issue that can appear in Xamarin.Android and Xamarin.iOS projects after an update from Visual Studio 2017 version 15.7 to version 15.8 Preview.
Example steps to demonstrate the issue
Create a new blank Xamarin.Android or Xamarin.iOS project.
Add the Microsoft.AspNetCore.SignalR.Client.Core version 1.0.0 NuGet package to the project.
Use a type from the NuGet package in the project. For example, add the following line to any existing method:
var connection = new Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder().Build();
For Xamarin.Android, attempt to build the project in the Debug configuration. For Xamarin.iOS, build and run the app in the Debug configuration on iPhone simulator.
Results with Visual Studio 2017 version 15.7
Both the Xamarin.Android app and the Xamarin.iOS app build and run without error.
Results with Visual Studio 2017 version 15.8 Preview 4
For Xamarin.Android, the build fails:
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.Connections.Abstractions`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.Connections.Abstractions`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Client.Core`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Client.Core`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Common`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Common`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.AspNetCore.SignalR.Protocols.Json`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.AspNetCore.SignalR.Protocols.Json`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `Microsoft.Extensions.Primitives`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `Microsoft.Extensions.Primitives`.
Xamarin.Android.Common.targets(1831,2): error XA2002: Can not resolve reference: `System.Memory`, referenced by `System.IO.Pipelines`. Please add a NuGet package or assembly reference for `System.Memory`, or remove the reference to `System.IO.Pipelines`.
For Xamarin.iOS, the app launches successfully on the simulator, but the debug output shows that the app fails to find System.Memory when it's running:
Could not find `System.Memory` referenced by assembly `System.IO.Pipelines, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Client.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.Extensions.Primitives, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.Connections.Abstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
Could not find `System.Memory` referenced by assembly `Microsoft.AspNetCore.SignalR.Protocols.Json, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60`.
How do I resolve these errors? As a follow-up, why did these errors appear after I updated Visual Studio?
I use VS Entreprise 2017 Version 15.9.1
To solve the problem I face ( Can not resolve reference: System.Buffers, referenced by System.Memory. Please add a NuGet package or assembly reference for System.Buffers, or remove the reference to System.Memory.),
I just install System.Buffers package by this command:
Install-Package System.Buffers -Version 4.5.0
https://www.nuget.org/packages/System.Buffers/
How do I resolve these errors?
To resolve these errors, update the Microsoft.AspNetCore.SignalR.Client.Core NuGet package to version 1.0.1 or higher in all the projects that use it. For example:
Go to Tools > NuGet Package Manager > Manage NuGet Packages for Solution > Updates.
Update Microsoft.AspNetCore.SignalR.Client.Core to version 1.0.1 or higher.
In Microsoft.AspNetCore.SignalR.Client.Core version 1.0.1, the System.Memory NuGet dependency is now (>= 4.5.1) rather than (>= 4.5.0). And because System.Memory version 4.5.1 no longer includes placeholder files for Xamarin project types, Xamarin projects will now use the .NET Standard 2.0 assembly directly from the NuGet package. This solves the errors because the Xamarin projects can now successfully locate the System.Memory reference.
As a follow-up, why did these errors appear after I updated Visual Studio?
The errors appeared because the Xamarin SDK versions in Visual Studio 2017 version 15.7 and version 15.8 have a tricky compatibility relationship with the System.Memory NuGet package versions. In Visual Studio 2017 version 15.7, Xamarin.Android and Xamarin.iOS use their own built-in implementations of the types from that NuGet package, so they don't need to reference the assembly from the NuGet package. The System.Memory NuGet package version 4.5.0 accordingly includes placeholder files for Xamarin project types to prevent conflicts.
But the built-in implementations in the current Xamarin SDK releases do not yet cover the full surface area of the NuGet package. So for Visual Studio 2017 version 15.8, the Mono team temporarily hid those built-in implementations (by switching them to internal and removing the System.Memory facade assembly). This means that Xamarin projects now depend on the implementations from the NuGet package instead. And the System.Memory NuGet package version 4.5.1 accordingly does not include placeholder files for Xamarin project types.
One more thing to keep in mind is that the built-in implementations in the Xamarin SDKs will cover the full surface area of the NuGet package in a future release. The built-in implementations will then be un-hidden and the placeholder files will be added back to the NuGet package. Users will need to update their NuGet packages once more when that happens. That next change will be coming in Visual Studio 2017 version 15.9 or later.

target 'MonoAndroid,Version=v6.0' project dependencies

My Visual studio 2017 nuget package can't install following error is occured in Xamarin.Forms Portable class library Project
Severity Code Description Project File Line Suppression State
Error Could not install package 'Xamarin.Android.Support.Compat 25.3.1'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v6.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. 0
Xamarin.Android.Support.Compat version 25.3.1 has dependencies of
MonoAndroid 7.0
Xamarin.Android.Support.Annotations (= 25.3.1)
Xamarin.Build.Download (>= 0.4.3)
Re: https://www.nuget.org/packages/Xamarin.Android.Support.Compat/25.3.1
You need to set the Target Framework to at least 7.0.
Re: https://developer.xamarin.com/guides/android/application_fundamentals/understanding_android_api_levels/#Target_Framework

Error while creating xamarin-component for android

I have used the command
xamarin-component.exe package C:\cmp\AndroidComponent\component
for creating Xamarin component.While building the Sample android project, it is showing the below error. (I have used the command xamarin-component.exe package C:\cmp\AndroidComponent\component -verbose to display the error message in detail).
Error message:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.targets(155,2): error MSB3644: The reference assemblies for framework "MonoAndroid,Version=v1.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\cmp\AndroidComponent\component\samples\App17\VidyoClientAndroid\VidyoClientAndroid.csproj]
Note:
I am able to create a Xamarin component for iOS source code successfully. • While creating the Xamarin component for Android source code, internally msbuild.exe is getting called from 64 bit folder(C:\Program Files (x86)\MSBuild\14.0\binamd64\msbuild.exe "/p:Configuration=Release" "C:\cmp\AndroidComponent\component\samples\App17\App17.sln"...). • Build is successful when msbuild.exe is called from path: “C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe”(32 bit) explicitly while building the android project explicity.

Getting the error "Error CS0234: The type or namespace name `CrossCore' does not exist in the namespace `Cirrious'

Getting the error "Error CS0234: The type or namespace name CrossCore' does not exist in the namespaceCirrious'. Are you missing an assembly reference?" for PCL. And unable to update packages.
We are getting error when we are trying to update packages in Xamarin studio PCL in Mac machine. “Could not install package 'MvvmCross.PortableSupport 3.2.2'. You are trying to install this package into a project that targets 'portable-Profile78', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.”
If you are updating an old MvvmCross project then that is probably why. Starting with 3.2.1 MvvmCross moved to PCL profile 259. You'll need to change the profile of your pcl core to this profile or something else that is compatible.
After uninstall xamarin by following steps in the url http://developer.xamarin.com/guides/cross-platform/getting_started/installation/uninstalling_xamarin/
and reinstall the Xamarin Studio, the Nuget packages are started updating.

Resources