Why does adding the Moq NuGet package generate a MT0109 warning - xamarin

I've started working on a vanilla Xamarin.Forms project, and I get the below warning when trying to build the iOS project, straight after adding Moq to the Forms project.
MTOUCH : warning MT0109: The assembly 'System.Diagnostics.TraceSource.dll' was loaded from a different path than the provided path (provided path: /Users/{me}/.nuget/packages/system.diagnostics.tracesource/4.3.0/runtimes/win/lib/netstandard1.3/System.Diagnostics.TraceSource.dll, actual path: /Library/Frameworks/Xamarin.iOS.framework/Versions/12.8.0.0/lib/mono/Xamarin.iOS/Facades/System.Diagnostics.TraceSource.dll).
There are no warnings reported when adding the NuGet package itself, only when building the iOS project. In fact, there were two warnings when building but I managed to fix one.
I've tried with various versions of Moq (4.7.x, 4.8.x, 4.9.x, 4.10.x). Same issue.
I've Googled extensively but it hasn't been much help. I came across the following threads which provided some insight but didn't actually help solve the issue:
How do I get rid of these compiler warnings about wrong paths
https://developercommunity.visualstudio.com/content/problem/121551/xamarin-ios-build-assembly-path-mismatch.html
https://github.com/dotnet/standard/issues/481
Questions: How can I resolve this warning? Is this an issue with Moq that needs a bug repro submitted?
My environment:
VS for Mac 2019 V8.0.4 (build 0)
Xamarin.Forms project uses
Xamarin.Forms 3.6.0.x, Xamarin.Essentials 1.0.1, Moq (causing the
warning), and the target framework is .NET Standard 2.0.

Related

Found conflicts between different versions of "System.Numerics.Vectors" in Xamarin Forms 5 project

I'm building a new Xamarin Forms 5 app using VS 2022 17.1.1. Everything in the project appears to be up-to-date.
I've been working on this project for a while and never had this issue. All of a sudden it just appeared today. The last action I took was to install the Plugin.InAppBilling package, thought the package in question is not used by the Plugin.InAppBilling package.
The error is as follows:
All I can see is that the shared project is using System.Numerics.Vectors version 4.5.0 and it seems to be dependency of Xamarin.Essentials which is version 1.7.1 in my project.
However, the version number of System.Numerics.Vectors seems to be 2.0.5.0 in the Android and iOS projects.
I found the GitHub issue here but I'm not seeing any clear resolution to this issue. Even though it appears to be a warning, in my case, I can no longer run the app because I keep getting deployment error to the Android Emulator or actual device. It simply refuses to deploy my app to the device/emulator. So, it's really NOT a warning in my case. It's a show-stopper. I'm a bit surprised about how lightly the Xamarin Essentials folks seem to have taken this issue on GitHub.
Has anyone actually resolved this issue? If so, what's the solution?
BTW, in my case both the Android and the iOS projects are throwing this error/warning and both use System.Numberics.Vectors version 2.0.5.0 even though the shared project has version 4.5.0 installed as a dependency undre Xamarin Esssentials.
I'd appreciate some pointers on how to make this issue disappear. Thanks.
At first, you can try to update the Xamarin.Essentials package in the Android and IOS project with the nuget package manager to the version 1.7.1.
And then, if the error is still here, you can right click the reference and remove the reference of the System.Numberics.Vectors 2.0.5.0 both in your Android and IOS project. Then download the System.Numberics.Vectors 4.5.0 in the nuget package manager both too.

Xamarin Forms on TeamCity: Xamarin.Forms tasks do not match targets

I am building a Xamarin Forms solution (containing an iOS library, an Android library and a .NET Standard library) in TeamCity.
I have just upgraded to Xamarin Forms 3.1.0.583944. The project builds without any problem locally, but on my TeamCity build server (Windows Server 2016), I'm consistently getting the following error:
C:\BuildAgent\work\f12265fda07473c1\src\packages\Xamarin.Forms.3.1.0.583944\build\netstandard2.0\Xamarin.Forms.targets(44,
3): error XF002: Xamarin.Forms tasks do not match targets. Please
ensure that all projects reference the same version of Xamarin.Forms,
and if the error persists, please restart the IDE.
I have tried downgrading Xamarin Forms, and rebooting the build agent. Neither of these has succeeded.
UPDATE: There is a new error:
C:\BuildAgent\temp\buildTmp.nuget\packages\xamarin.forms\3.0.0.561731\build\netstandard2.0\Xamarin.Forms.targets(44, 3): error XF002: Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE.
For some reason, the agent is looking for Version 3.0.0.561731. But that is no longer anywhere in the project. I had deleted the entire C:\BuildAgent\temp\buildTmp\.nuget\packages\xamarin.forms\3.0.0.561731 folder, but it has come back.
ADDENDUM: I notice that every time I upgrade Xamarin.Forms to this version via NuGet, it fails to uninstall the old package, and I have to restart Visual Studio to complete the process. This happens without fail. I am fairly sure this is connected to the breaking build, but that is more due to speculation and experience than concrete analysis.
I found out how to fix the problem, but it's not clear to me why it would manifest in the way it has -- locally and even when I RDP onto the build agent, it builds without trouble, but when I run the build agent from the TeamCity console I hit these compilation errors.
One of my dependencies is a NuGet package, which itself has a dependency on Xamarin Forms. Fortunately, I own that NuGet package, and was able to upgrade its Xamarin Forms version to the latest available package. If I didn't own that package I would be completely stuck though -- so this is only a partial solution.
The above answer was quite helpful for me . I would like to add a couple of additional notes though. I was facing this issue when I was using Xamarin Forms 3+ and my local build was being really inconsistent with the same error "Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE.". Then I cleared my local NuGet cache and rebuilt the project and saw that there were other NuGet package versions being pulled for Xamarin Forms when I did a NuGet restore. I then reversed the ordering of the NuGet packages starting with Xamarin Forms and it all worked fine.

Xamarin.iOS app will not build to device but does build to simulator; Realm issue?

I get the following build error when targeting an iOS device:
MTOUCH : error MT2101: Can't resolve the reference 'System.Void* System.Runtime.CompilerServices.Unsafe::AsPointer(!!0&)', referenced from the method 'T Realms.MarshaledVector`1::MarshalElement(System.Int32)' in 'System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Specifically I think the reference is made here: T Realms.MarshaledVector
This builds fine on the simulator but it fails when targeting the device. The Realm NuGet Package is installed. In fact I just removed it and re-installed it to see if that might fix it; it didn't.
Anyone know anything else to try to make this run or what could cause this build error only when the target is a device?
iOS version: 11.2.1 (15C153)
OSX version: 10.13.2
Visual Studio Community Version: 7.3.2 (build 12)
Xcode: 9.2 (9C40b)
... later ...
Ok it appears like it's definitely realm. Even the act of doing this:
using Realms;
var settingsFilename = "/some/path/settings.realm";
var Config = new RealmConfiguration(settingsFilename);
Causes Visual Studio Community to fail to build the project with the error mentioned above. I have this code in my AppDelegate FinishedLaunching.
Next up I'm gonna try and strip everything away in there and see what happens I guess.
... later ...
Ok the reference error is different now at least.
MTOUCH : error MT2101: Can't resolve the reference 'System.Void* System.Runtime.CompilerServices.Unsafe::AsPointer(!!0&)', referenced from the method 'T Realms.MarshaledVector1::MarshalElement(System.Int32)' in 'System.Runtime.CompilerServices.Unsafe, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Error processing method: 'T Realms.MarshaledVector1::MarshalElement(System.Int32)' in assembly: 'Realm.dll'
Failed to resolve System.Void* System.Runtime.CompilerServices.Unsafe::AsPointer(!!0&)
It specifically calls out: in assembly: 'Realm.dll'
So at least for now what I did, after this ate my entire day leaving me with 0 progress. I started a new project, installed the same dependencies
Realm (2.1.0)
Serilog (2.6.0)
Serilog.Sinks.Xamarin (0.1.29)
System.Reactive (3.1.1)
Xam.Plugin.Connectivity (3.0.3)
Xamarin.Auth (1.5.0.3)
No Error.
So I went back to my customer's project, deleted all the packages from packages.config and re-installed them all. It doesn't seem to have this build error any longer (Can't resolve the reference 'System.Void* ...).
It occasionally seems to fail to deploy to the device properly under debug scenarios with the following error:
dyld: Library not loaded: #rpath/libmonosgen-2.0.dylib
But cleaning the project and trying again, seems to fix it. Also I can turn off Incremental Builds under:
Project Settings -> Build -> iOS Build -> Enable Incremental Builds
And that will also get past he dyld loading issue.
Per this other questions, Visual Studio Community missing developer tools for iOS 11.2.1, cannot debug, a commenter also recommends just unloading the project from the solution and reloading it to solve the problem as well.
So I'm going to count my blessing and just keep going until it blows up again. I should note this did happen AFTER I upgraded Visual Studio Community in the middle of this project to: 7.3.2 (build 12). Again, it only seemed to happen when trying to debug on a device, in this case an iPhone X running iOS 11.2.1 (15C153). I have yet to try on other devices/os versions yet, since again, this literally consumed my whole day yesterday.
Same error with Realm 2.0.0.
How i fixed it :
Installed the NuGet package System.Runtime.CompilerServices.Unsafe
Removed the System.Runtime.CompilerServices.Unsafe lib in project
references
Re-add the lib manually by selecting the file System.Runtime.CompilerServices.Unsafe.dll located in packages folder
project. (the one installed in step 1)
Hope it'll help !

Using EF7 SQLite on Android 7+

In my project, I am using the Microsoft.EntityFrameworkCore.SQLite package from NuGet. But for Android 7+, the app crashes with unauthorized access to "/system/lib64/libsqlite.so".
This is because Android 7 doesn't allow native libraries other than the ones in their NDK (as far as I understood). Also see this issue: https://github.com/aspnet/EntityFramework/issues/7777.
So, I researched the internet for about 2 days now and unsuccessfully tried a bunch of things to get EFCore to work on Android 7. One of them was to update to the preview version v2.0.0-preview1-final. But this resulted in other problems like the following where the app compiled, but crashed while deploying/starting on the emulator:
06-21 09:58:18.970 D/Mono ( 3632): Assembly Loader probing location: 'System.Runtime.CompilerServices.Unsafe'.
06-21 09:58:18.970 F/monodroid-assembly( 3632): Could not load assembly 'System.Runtime.CompilerServices.Unsafe' during startup registration.
06-21 09:58:18.970 F/monodroid-assembly( 3632): This might be due to an invalid debug installation.
I then tried to add the 'System.Runtime.CompilerServices.Unsafe' NuGet package manually to my project, but it didnt fix the problem.
I messed around a lot, trying different build parameters and such and actually got the app running with the preview package of EFCore on an Android 7 emulator. However, after a project clean and rebuild, the error showed up again.
Any help on how to get EFCore Sqlite to work on Android 7?
I am using Visual Studio 2017 with Xamarin.Android 7.3.1.2
I created an example project in order to reproduce the issue: https://github.com/tipa/EFCoreSample - Basically just started with the basic Android template from VS and added the Nuget package
I know this was asked more than two months ago and you've probably found the solution, but I've wanted to post how we've managed to get around this issue.
We are developing a Xamarin.Forms application with EntityFrameworkCore and SQLite. Due to project and company policies, we are restricted to using .NetStandard 1.6 (we migrated our PCL projects from .NetFramework to .NetStandard in order to integrate EntityFrameworkCore).
After this issue started happening to us, we managed to fix this by doing the following:
Updating "Microsoft.EntityFrameworkCore" and "Microsoft.EntityFrameworkCore.SQLite" from version "1.1.1" to "2.0.0-preview1-final" (this is the latest version that works with .NetStandard 1.6) in the DAL project (we have a separate PCL project that contains the Context, UoW, Repositories and Models)
Updating just "Microsoft.Data.Sqlite" (this automatically updates the needed dependencies) from version "1.1.1" to "2.0.0-preview1-final" in the main Xamarin.Forms Android project
EntityFrameworkCore versions 2.x.x use the Android 7+ "approved" way of accessing the "libsqlite.so" file, while versions 1.x.x do not.
Hope this is of help to anyone who might use similar packages that we had.
I had the same issue and I found a solution to this problem.
I'm using Xamarin.Forms applications with .Net Standard 2.0 libs and using EFCore with SQLite. All you have to do is edit your Android csproj and add this after the last PropertyGroup tag:
<PropertyGroup>
<NoWarn>$(NoWarn);NU1605</NoWarn>
</PropertyGroup>
And then add the reference for System.Runtime.CompilerServices.Unsafe in csproj:
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.3.0" />
Clean and Rebuild your Android Project.
I found the answer to the problem here: https://developercommunity.visualstudio.com/content/problem/152947/xamarin-android-run-error-could-not-load-assembly.html

error : Error initializing task XamlG: Not registered task XamlG

I am developing a Xamarin Forms (PCL) application for IOS and Android Platform.
My Xamarin Studio version is 5.5.4 (Build 15). I am on stable channel.
My Xamarin Forms dll version is 1.3.0.6292.
I have also added a Xamarin Forms Labs reference from NuGet, v1.2.0.
Since yesterday, whenever i am building the solution, i get following error:
error : Error initializing task XamlG: Not registered task XamlG.
Any possible resolution for this error? I have tried clean and build multiple time. Even deleted the entire source code and redownloaded everything from source control but same error.
This error can occur if you have upgraded from an older version of Xamarin.Forms to a newer version. The underlying problem is that the wrong Xamarin.Forms.Build.Tasks.dll is being loaded compared with the one that the custo MSBuild Xamarin.Forms.targets file is expecting.
There is a bug in Xamarin Studio where the old build Xamarin.Forms build tasks are still used after the NuGet package has been upgraded. You can workaround this by closing and re-opening the solution.
However you say you have deleted the source code and downloaded everything again so it sounds like you have a different problem. It may be that your project is trying to use two different versions of Xamarin.Forms at the same time. I would look at your project files (.csproj) in a text editor and make sure they are all using one version of Xamarin.Forms. Check that they are all referencing a single version of Xamarin.Forms.targets and it is the same version.
This is silly.
I just recloned the project in a new fresh folder and build it from scratch and it worked. The more i am using Xamarin Forms, the more buggy and unbaked it seems. There are random issues which get fixed just by rebuilding the project. Or like Matt pointed in his answer below, by just restarting the studio. In my programming experience with different IDEs and platforms, only Xamarin seems to have these problems regularly.

Resources