Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

DependencyService throwing constructor Error

$
0
0

In Xamarin Forms i have a solution like this:

Solution
         |- Services
         |   |- IFileSystem.cs
         |   |- Etc.
         |
         |- Forms.App
         |   |- LoginPage.cs
         |   |- Etc.
         |
         |- Forms.App.iOS
         |   |- iOSFileSystem.cs
         |   |- Etc.
         |
         |- Forms.App.Android
         |   |- DroidFileSystem.cs
         |   |- Etc.

All "Forms.App" projects references the services project, which my interface lives (It is part of a larger system that need it to live there).

Interface Code:

`
namespace MyCompany.Services.Interfaces
{

public interface IFileSystem
{
    bool DoesFileExist(string filename);
}

}
`

iOS Implementation:

`
using System;
using System.Diagnostics;
using System.IO;

using MyCompany.Services.Interfaces;
using MyCompany.Services.Interfaces.Classes;

[assembly: Xamarin.Forms.Dependency(typeof(MyCompany.Mobile.ios.iOSFileSystem))]

namespace MyCompany.Mobile.ios
{
using Foundation;
[Preserve]
public class iOSFileSystem : MyCompany.Services.Interfaces.IFileSystem
{
public iOSFileSystem(){ }

    public bool DoesFileExist(string filename)
    {
        return File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + filename);
    }

}

}
`

Usage:
var mobileFileSystem = DependencyService.Get<MyCompany.Services.Interfaces.IFileSystem>();

When I run this last line of code, I get the following error:
"Default constructor not found for type MyCompany.Mobile.ios.iOSFileSystem."

I don't understand why this error is happening because there is a default constructor in iOSFileSystem. Anyone have any ideas whats going on?


Viewing all articles
Browse latest Browse all 58056

Trending Articles