Can't find interface for dependency injection in iOS

JesseLibertyJesseLiberty USInsider, University ✭✭✭

Hi,

This, I hope is easy. I am using dependency injection to find the file path for both file storage and for SQLite. It works great on Android bu on iOS it says it can't find the interface. Is this known? Am I doing something stupid?

[assembly: Dependency( typeof( FileImplementation ) )]
namespace DartEDriver.iOS
{
   public class FileImplementation : IFile

It rejects the using statement that points to the interface (grey's it out). And while we're at it, is it grey or gray?

Thanks again.

Best Answer

  • JesseLibertyJesseLiberty US ✭✭✭
    Accepted Answer

    @sonny_ppg Nope, didn't but rolling back a couple small checkins did it. The code that was causing the problem can't possibly cause that problem, but nonetheless, take it out and it works, put it back in and it fails. Grrr.

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    @JesseLiberty said:
    Hi,

    This, I hope is easy. I am using dependency injection to find the file path for both file storage and for SQLite. It works great on Android bu on iOS it says it can't find the interface. Is this known? Am I doing something stupid?

    [assembly: Dependency( typeof( FileImplementation ) )]
    namespace DartEDriver.iOS
    {
       public class FileImplementation : IFile
    

    It rejects the using statement that points to the interface (grey's it out). And while we're at it, is it grey or gray?

    Thanks again.

    That setup looks fine. If for some reason you don't have reference to the PCL from your iOS project,

    Right click on References in your iOS Project > Edit References > Projects > Tick your PCL project > Ok

    Just make sure all the methods in the IFile.cs match up with the ones in FileImplementation.cs too or it'll throw some errors.

  • JohnHardmanJohnHardman GBUniversity mod
    edited November 2017

    @JesseLiberty - I find myself coding in American "English" rather than British English these days, switch depending on locale in my UI, and normally use American in this forum, so if following suit for the forum, the color is gray rather than the colour is grey :-)

    I do still use "whilst" occasionally, just to mix things up ;-)

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭

    @seanyda Thanks. I have done all that... the references in the iOS project show the reference to the PCL project. This is truly weird. I'll keep at it, thanks.

  • JohnHardmanJohnHardman GBUniversity mod
    edited November 2017

    @JesseLiberty said:
    Hi,

    This, I hope is easy. I am using dependency injection to find the file path for both file storage and for SQLite. It works great on Android bu on iOS it says it can't find the interface. Is this known? Am I doing something stupid?

    [assembly: Dependency( typeof( FileImplementation ) )]
    namespace DartEDriver.iOS
    {
       public class FileImplementation : IFile
    

    It rejects the using statement that points to the interface (grey's it out). And while we're at it, is it grey or gray?

    Thanks again.

    "it says it can't find the interface" - at build time or runtime? If build time, what's the error it reports? If runtime, can you show the code for IFile, including the usings and namespace?

    Without knowing that, you might want to add the namespace into the typeof, so typeof(DartEDriver.iOS.FileImplementation)

  • JohnHairJohnHair GBMember ✭✭✭✭✭
    edited November 2017

    @JesseLiberty I had a similar issue recently, had to close VS and reopen for it to be recognized.

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭

    I swear that it spontaneously broke, and just as spontaneously fixed itself. Xamarin is haunted. Now I'm getting "ResolveLibraryProjectImports" task failed unexpectedly. I weep

  • sonny_ppgsonny_ppg USMember, University ✭✭

    Try cleaning the solution then close VS and then delete the obj and bin folders. Reopen the solution and see if that fixed it.

  • JesseLibertyJesseLiberty USInsider, University ✭✭✭
    Accepted Answer

    @sonny_ppg Nope, didn't but rolling back a couple small checkins did it. The code that was causing the problem can't possibly cause that problem, but nonetheless, take it out and it works, put it back in and it fails. Grrr.

  • onraltnonraltn Member

    Solved the problem. After latest Xamarin update, You have to add Portable Class reference into Android and iOS references.

Sign In or Register to comment.