Forum Xamarin.Forms

Dependecy service get interface

GoncaloLopesGoncaloLopes PTMember ✭✭

I´m using cross platform project and i need to delegate a specific code for teh android project and i create an interface

namespace SilenceTv1._0
{
public interface ISoundPlayer
{

    void Play();
}

}

and in a Button_Clicked event do this line but send me an error
DependencyService.Get().Play();

throws "System.MissingMethodException: Default constructor not found for type SilenceTv1._0.ISoundPlayer"

SilenceTv1._0.ISoundPlayer its a interface dont have constructor right?

Best Answer

  • GoncaloLopesGoncaloLopes PTMember ✭✭
    Accepted Answer

    I solved, the problem was in [assembly: Dependency(typeof(AudioImplementation))]
    In typeof i had the name of the interface but is the name of the class

Answers

  • DiogoLeaoDiogoLeao USMember ✭✭

    DependencyService.Get<ISoundPlayer>().Play();

  • GoncaloLopesGoncaloLopes PTMember ✭✭
    Accepted Answer

    I solved, the problem was in [assembly: Dependency(typeof(AudioImplementation))]
    In typeof i had the name of the interface but is the name of the class

  • Many thanks GoncaloLopes! Same error here. What a stupidity :disappointed:

Sign In or Register to comment.