Main Site Documentation

How to get the Main executing assembly from a library in NetMF


#1

Hello, I’ve tried


Debug.Print(System.Reflection.Assembly.GetExecutingAssembly().GetName().FullName.ToString());

But this returns the current assembly the method is called from.
For example, I have a “CommonLibrary” that I would like it to get the mainAssembly name automatically. (for logging purpose).
I have 5+ different main projects, that all use the “CommonLibrary”.

The Title/Description/Company/Product/etc info in the AssemblyInformation from the ConsoleApplication would work also.

Is there a way for a library to obtain this information?

My Plan B is to set in my “CommonLib” the executing App name from the Main, example:


 CommonLib.SetMainAssemblyName("MyBlinkingLedApp");

But I would like to refrain from doing that…


#2

I’m not going to be able to assist directly here, but Skewworks has a number of frameworks for app loading and he may have already included in the things he’s open sourced things you can learn from. Pyxis2 would be where I’d start looking…


#3

Hi,
Check out my exception logger here;

http://wiki.tinyclr.com/index.php?title=User:Jay_Jay

you should find what you are looking for in there.

cheers,


#4

Thanks Jay, that’s a nice little piece of code :slight_smile:
Might be useful to log exceptions that might happens on devices that are on the field.

However I quickly went through it, you also use System.Reflection.Assembly.GetExecutingAssembly(); , which I already tried, it returns the current assembly that the method is called from, not the executing assembly where the Main is (or Gagdegetter Program). It works though if you use it in the main Program like you did.

What I’m trying to do is that the library itself could know the main assembly (startup program). It might not be possible.

For now I just made a method to my logger that I call from my main, and set the executable name there.

Maybe I missed something from your code though?


#5

Hi Phil,
You’re welcome :slight_smile:
Did you notice how i pass the assembly as an object to the class? This is how i get the name correctly, checkout the arguments…

Cheers,
Jay.


#6

Yes I did see it, that’s what I was trying to avoid (passing stuff from the main executable to my library, I wanted my library to find the information of the main program from itself.

But it might not be possible, so I’ll just pass it for now.
Thanks