1

I'm trying to use SQlite-net-pcl to store some data. As I read from different posts, I have to create an interface service on my main project and then implementing from that service on my Android and iOS projects. The issue happens when I try to implement the interface on the Android or iOS project:

namespace DemoApplication.iOS { public class LocalFileHelperService : ILocalFileHelperService { } } 

Error CS0246 The type or namespace name 'ILocalFileHelperService' could not be found (are you missing a using directive or an assembly reference?)

But when I try to add the reference:

using DemoApplication.Services; 

I get the following error:

Error CS0234 The type or namespace name 'Services' does not exist in the namespace 'DemoApplication' (are you missing an assembly reference?)

Am I doing anything wrong? I remember that using another framework that was the correct form to implement services in Android and iOS platforms, but now in MvvmCross seems that is made different.

Does anyone knows how is the correct form to do it?

Thanks in advance.

EDIT:

I attach the interface definition.

namespace DemoApplication.Services { public interface ILocalFileHelperService { string GetLocalFilePath(string fileName); } } 
10
  • Does your iOS project have a reference to the shared project containing ILocalFileHelperService? Commented Apr 8, 2018 at 13:59
  • Your approach seems correct. Can you confirm that your ILocalFileHelperService existing in the main core project, and that it is public access modifier type? Additionally, if you do a rebuild on your main project does the interface perhaps then show up in your platform projects? Commented Apr 8, 2018 at 14:00
  • @Jason yes it has.Android and IOS Project both have the reference to the DemoApplication Project (which is where I have the public interface created). Commented Apr 8, 2018 at 14:06
  • @Plac3Hold3r I edited the post with the Interface definition. What do you refer when you say platform Project? Commented Apr 8, 2018 at 14:07
  • @flaurens I was just curious if you where to compile the main project which has your interface if after compile you where to then be able to access your interface in your Android or iOS project (i.e. platform projects). Commented Apr 8, 2018 at 14:12

1 Answer 1

1

Sometimes when adding a new .NET Standard class library to your a solution Visual Studio's intellisense will not pick up changes to code in your .NET Standard class library from reference projects. Restarting Visual Studio seem to resolve the issue.


In terms of your second question

Do you know how I have to register the Interfece or beeing an mvvmcros Project it's not necessary?

It is necessary. MvvmCross provides options inside of your Setup.cs class allowing you to register your platform specific implementation against an common interface defined in your core project.

  • InitializeFirstChance
  • InitializeLastChance

For many objects the choice of when to initialize - first or last - doesn’t matter. For others, the key choice is whether the service needs to be available before or after the App is created and initialized.

Example

protected override void InitializeFirstChance() { Mvx.LazyConstructAndRegisterSingleton<ILocalFileHelperService, LocalFileHelperService >(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.