1

I'm trying to add an image from my phone gallery but keep getting a System.Reference, and I want to upload an image from my phone gallery when pressing on a button, and it gives a nullReferenceException on DependencyService.

MyPage:

InitializeComponent();


        Device.OnPlatform(
            Android: () => {
                new Thickness(0, 20, 0, 0);
                }
        );

        Image image = new Image();

        Button addImage = new Button { Text = "Select Image" };
        addImage.Clicked += (sender, args) =>
        {
            IGalleryImageService galleryService = DependencyService.Get<IGalleryImageService>();
            galleryService.ImageSelected += (o, imageSourceEventArgs) => image.Source = imageSourceEventArgs.ImageSource;
            galleryService.SelectImage();

        };

        this.Content = new StackLayout
        {
            Children =
            {
                image,
                addImage
            }
        };
Sylar
  • 23
  • 1
  • 5

1 Answers1

4

You probably forgot to export the implementation by adding the right attribute.

Do you have this above your namespace declaration in the GalleryImageService_Android.cs file?

[assembly: Xamarin.Forms.Dependency (typeof (GalleryImageService_Android))]

Gerald Versluis
  • 21,913
  • 5
  • 52
  • 75