I'm trying to implement some platform-specific code in Xamarin, using this answer, but I ran into an issue with setting the platform-specific class to a Dependency. I get the following compiler error, underlined the assembly
word of the tag:
Assembly and module attributes must precede all other elements defined in a file except using clauses and extern alias declarations.
I have the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Security.Permissions;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using ZXing.Net.Mobile.Forms;
using Xamarin.Forms;
namespace MyApp_Xamarin.Droid {
[assembly: Dependency(typeof(View.ActualPage.BarcodeScannerTest))]
public class BarcodeScannerTestClass : View.ActualPage.BarcodeScannerTest
{
public async void Start(INavigation nav, Page page)
{
var scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
// Stop scanning
scanPage.IsScanning = false;
// Pop the page and show the result
Device.BeginInvokeOnMainThread(() =>
{
nav.PopAsync();
page.DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
// Navigate to our scanner page
await nav.PushAsync(scanPage);
}
}
}
What am I missing?
As the error says the assembly attribute has to be declared before most other program elements in the file. The namespace declaration (namespace MyApp_Xamarin.Droid
) is one of these elements. You have to move the attribute before that:
[assembly: Dependency(typeof(View.ActualPage.BarcodeScannerTest))]
namespace MyApp_Xamarin.Droid
{
public class BarcodeScannerTestClass : View.ActualPage.BarcodeScannerTest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With