Essentials: Xamarin.Essentials.NotImplementedInReferenceAssemblyException raised in test project

Created on 13 Jun 2019  路  5Comments  路  Source: xamarin/Essentials

Description

I have a Xamarin Forms project that uses Xamarin Essentials v1.1.0. We created an IXamarinEssentials interface to wrap around the Xamarin Essentials calls so that they can be mocked as recommend in below article:
https://github.com/xamarin/Essentials/wiki/FAQ-%7C-Essentials#where-are-the-interfaces

However, as soon as we debug any NUnit Test case it the test case crashes with below exception even when there is no reference or requirement for Xamarin Essentials in that test case:

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.

I am sure this was working in earlier version (don't remember the exact version).

Similar issue was closed (https://github.com/xamarin/Essentials/issues/520) but recommended steps did not work.

Steps to Reproduce

  1. Create a sample Xamarin Forms project
  2. Add reference to Xamarin.Essentials to the shared library (.NET standard 2.1)
  3. Add a NUnit test project, add a sample test case and try to debug it.

Expected Behavior

The test case should execute. Only test cases that hits the actual call to Xamarin.Essentials should fail and it is developers responsibility to mock that call.

Actual Behavior

The test runner stops (crashes) with Xamarin.Essentials.NotImplementedInReferenceAssemblyException exception

Reproduction Link

Most helpful comment

Sorry for the false alarm. Deep inside our code Xamarin Essentials was used directly, which was causing my test project to crash.
Once we fixed our code to get rid of that lime, we were able to run test cases.
All good now.

All 5 comments

Xamarin Essentials uses functionality from iOS/Android themselves. A test project cannot provide such functionality.

Xamarin Essentials uses functionality from iOS/Android themselves. A test project cannot provide such functionality.

I don't want that functionality in Test Project. We would mock any call to Xamarin Essentials but that doesn't mean the test runner should fail

You should #ifdef out Xamarin.Essentials.Platform.Init calls.

Do you know on what line of code it is crashing? Do you have a repro that I can look at?

Sorry for the false alarm. Deep inside our code Xamarin Essentials was used directly, which was causing my test project to crash.
Once we fixed our code to get rid of that lime, we were able to run test cases.
All good now.

Was this page helpful?
0 / 5 - 0 ratings