Essentials Preferences and unit tests

I'm doing a Core2.1 Xamarin.forms app. I added Essentials so I could save some settings to the preferences. I have added it to my main code, written a unit test and I now get an error (NotImplementedInReferenceAssemblyException) when i run the test.

By the look it has been implemented for everything except netstandard (core??). All my other unit tests that call the classes that use this code will now get the exception. How do i unit test it? It works on iOS fine.

Answers

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    NotImplementedInReferenceAssemblyException that occurs when executed from a reference assembly. This usually means that the NuGet was not installed into the app project.But it works on iOS fine,this most likely means that when you installed it you were not targeting Xamarin.Android 8.1 as your compile target . Try to uninstall and set your project: https://blog.xamarin.com/android-apps-google-play-target-api-level-requirements/ , then install again.

  • shaunpryszlakshaunpryszlak USMember ✭✭

    When you run unit tests, don't they just run as c# on whatever platform you are running Visual Studio on? In this case it was a Mac. I haven't tried it on a Droid yet.

  • shaunpryszlakshaunpryszlak USMember ✭✭
    edited February 28

    I am already on android 8.1. Back on my PC i added Essentials to all my projects (app, library, tests and platforms) in the solution. No luck. The error message states

    Xamarin.Essentials.NotImplementedInReferenceAssemblyException : This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

    What does "You should reference the NuGet package from your main application project in order to reference the platform-specific implementation." mean? Does that just mean, add the same version?

  • yelinzhyelinzh Member, Xamarin Team Xamurai

    I assum you mean the Xam.Plugin.Connectivity NuGet package since there is no Xam.Plugin.CrossConnectivity NuGet package.

    The PCL assemblies in the Xam.Plugin.Connectivity have no implementation so at runtime your Android or iOS application needs to use the Xam.Plugin.Connectivity assemblies that are compiled for Android or iOS. So you need to install the Xam.Plugin.Connectivity NuGet package into your Android and iOS projects.

  • shaunpryszlakshaunpryszlak USMember ✭✭

    My app and my library are ".Net Standard 2" while my xUnit tests project is ".Net Core 2.0". Droid and iOS are Droid and iOS projects. If that makes any difference. This is really an issue as I do TDD and half my tests don't work. If my app is essentially "Standard 2" then how do I run tests if Essentials doesn't implement "Standarsd 2"?

Sign In or Register to comment.