Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin -> System.Reflection.Assembly.GetExecutingAssembly doesn't work

I try to include a .csv file in my xamarin.forms project. The problem is, that I think it's only available for all the platforms at once when I use the file as an embedded resource. My assembly only has three methods:

Equals()
Load()
ReferenceEquals()

But I need Assembly.GetExecutingAssembly() to get my code to work.

Do you know how to solve this? Or maybe an alternative? Btw: I work with Visual Studio 2013 Ultimate and the trial License of Xamarin.Android/iOS

Edit: I guess it has to do sth. with Xamarin.Forms. A normal Desktop Application hast the Assembly.GetExecutingAssembly(); and it works fine, but I need it in my App :(

Edit 2: I try out this now: http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/files/#Loading_Files_Embedded_as_Resources

like image 865
Hendrik Avatar asked Oct 21 '14 06:10

Hendrik


People also ask

What is assembly GetExecutingAssembly ()?

In C#, GetExecutingAssembly() method is the method of Assembly class. This method returns the assembly that contains the code that is currently executing. To use this method we have to use System. Reflection in our program.

What is System reflection assembly?

Namespace: System.Reflection. Summary. Defines an Assembly, which is a reusable, versionable, and self-describing building block of a common language runtime application. C# Syntax: [Serializable]

How do you access the assembly of a running application?

The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type. Assembly property of a type found in the assembly, as the following example illustrates. To get the assembly that contains the method that called the currently executing code, use GetCallingAssembly.

What is the method to load assembly by name?

Loads an assembly given its AssemblyName. The assembly is loaded into the domain of the caller using the supplied evidence. Loads the assembly with a common object file format (COFF)-based image containing an emitted assembly. The assembly is loaded into the application domain of the caller.


1 Answers

Do it this way:

var assembly = typeof(App).GetTypeInfo().Assembly;

Being 'App' the type of your application file.

I've done exactly what you want (reading a csv file) this way.

like image 88
Dpedrinha Avatar answered Oct 03 '22 04:10

Dpedrinha