[Mono-dev] mkbundle & Assembly.GetEntryAssembly()

Rick Tillery rtillerywork at gmail.com
Mon May 15 20:14:42 UTC 2017


I checked the archives, but didn't see a reference to this issue (within
the last few years).

I have a project with a need to validate the assembly that is its entry
point.

Using Assembly.GetEntryAssembly() works for a stand-alone EXE, both in
Windows and in Linux (launched with "$ mono app.exe") but the path returned
by Assembly.CodeBase is for the EXE when I use mkbundle.

I've distilled the issue down to the following code, but in the project,
the path is used to check for a signed entry assembly.  mkbundle is needed
for several unrelated reasons, which would be difficult to address in other
ways.

$ cat assytest.cs
using System.Reflection;

public class Test
{
    public static void Main()
    {
        Assembly thisassy = Assembly.GetEntryAssembly();
        System.Console.WriteLine("Assembly Type: " + thisassy.GetType());
        System.Console.WriteLine(" CodeBase: " + thisassy.CodeBase);
        System.Console.WriteLine(" FullName: " + thisassy.FullName);
        System.Console.WriteLine(" Location: " + thisassy.Location);
    }
}
$ mcs assytest.cs

Any of these bundles provide the same output:
$ mkbundle -L /usr/lib/mono/4.5 -o assytest-noargs assytest.exe
$ mkbundle -L /usr/lib/mono/4.5 -o assytest-deps --deps assytest.exe
$ mkbundle -L /usr/lib/mono/4.5 -o assytest-static --static assytest.exe
$ mkbundle -L /usr/lib/mono/4.5 -o assytest-staticdeps --static --deps
assytest.exe
$ rm assytest.exe
$ ./assytest-staticdeps
Assembly Type: System.Reflection.MonoAssembly
 CodeBase: file:///home/user/*assytest.exe*
 FullName: assytest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
 Location: assytest.exe

The EXE itself, launched with mono returns nearly the same thing:
$ mcs assytest.cs
$ mono assytest.exe
Assembly Type: System.Reflection.MonoAssembly
 CodeBase: file:///home/user/assytest.exe
 FullName: assytest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
 Location: */home/user/*assytest.exe

The problem is that this means the entry assembly being returned is not the
actual entry point, and I don't see a way to determine the assembly that is
the correct entry point.

Any suggestions?

Thanks,
Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-devel-list/attachments/20170515/0c99ebc4/attachment.html>


More information about the Mono-devel-list mailing list