Search code examples
c#xamarinxamarin.formsportable-class-library

System.Reflection.Assembly does not contain a definition for 'GetExecutingAssembly'


I am trying to create Mobile App Using Xamarin.Forms (Portable Class Library), On the following Code, I can not use `GetExecutingAssembly:

    using System;
    using Xamarin.Forms;
    using Xamarin.Forms.Xaml;
    using System.Reflection;
    using System.IO;
    using PCLStorage;    

    namespace MnakbAlshaba
    {
        public class BookPage : ContentPage 
        {

            //      
            private void SetBookPagesRows()
            {
                var assembly = typeof(BookPage).GetTypeInfo().Assembly.GetExecutingAssembly();//error
                var resourceName = "MyCompany.MyProduct.MyFile.txt";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string result = reader.ReadToEnd();
                }
            }
        }
    }

I Get the following Error:

'System.Reflection.Assembly' does not contain a definition for 'GetExecutingAssembly' and no extension method 'GetExecutingAssembly' accepting a first argument of type 'System.Reflection.Assembly' could be found (are you missing a using directive or an assembly reference?) C:...

What should I do?


Solution

  • var assembly = Assembly.GetAssembly(typeof(BookPage));