Solved

Merging .NET assemblies using ILMerge

Posted on 2009-07-10
3
1,034 Views
Last Modified: 2013-11-26
I am having trouble making ILMerge merge several assemblies into one. Even when I create a completely stripped down solution with three basic projects, the executable doesn't behave.

The ILMerge command runs without error:
ilmerge /target:winexe /out:ModuleMerging.exe Com.Fjaer.Test.ModuleMerging.Console.exe Com.Fjaer.Test.ModuleMerging.Library1.dll Com.Fjaer.Test.ModuleMerging.Library2.dll

However, when running the new exe, it crashes when it reach the line System.Console.ReadKey(); As it crashes immediately, I haven't been able to attach and debug the application at the point where it crashes, so I don't have an Exception that explains what happens.

Also, when I comment out the line the crashes, the rest of the code doesn't seem to run at all. When running the original exe the WriteLine statements are printed as expected:
In Class2
In Class1
In Program
... while the exe created by ILMerge prints nothing, but still exits without any exception or error code.

I'm theorizing that there must be something either about the security settings on the new assembly, or that the new assembly doesn't have a starting point telling it to run Main().

The test solution can be found here:
http://www.sharefile.org/showfile-1565/comfjaertestmodulemerging.zip
The ILMerge.exe command runs post-build.

ILMerge:
http://www.microsoft.com/downloads/details.aspx?FamilyID=22914587-B4AD-4EAE-87CF-B14AE6A939B0&displaylang=en

Any advice?

Thanks,
Håvard Fjær
www.fjær.no

// Project: Com.Fjaer.Test.ModuleMerging.Console
// References: 
//  - System 
//  - Com.Fjaer.Test.ModuleMerging.Library1
using Com.Fjaer.Test.ModuleMerging.Library1;
 
namespace Com.Fjaer.Test.ModuleMerging.Console
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var class1 = new Class1();
            System.Console.WriteLine("In Program");
            // System.Console.ReadKey();
        }
    }
}
 
 
 
// Project: Com.Fjaer.Test.ModuleMerging.Library1
// References: 
//  - System 
//  - Com.Fjaer.Test.ModuleMerging.Library2
using System;
using Com.Fjaer.Test.ModuleMerging.Library2;
 
namespace Com.Fjaer.Test.ModuleMerging.Library1
{
    public class Class1
    {
        public Class1()
        {
            var class2 = new Class2();
            Console.WriteLine("In Class1");
        }
    }
}
 
 
 
// Project: Com.Fjaer.Test.ModuleMerging.Library2
// References: 
//  - System 
using System;
 
namespace Com.Fjaer.Test.ModuleMerging.Library2
{
    public class Class2
    {
        public Class2()
        {
            Console.WriteLine("In Class2");
        }
    }
}

Open in new window

0
Comment
Question by:havard-fjaer
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
dericstone earned 500 total points
ID: 24832042
Your sample application is a console application but the ilmerge command-line option /target:winexe tells ilmerge to create a Windows application. Instead, change to the command-line option to /target:exe to create a console application.
0
 
LVL 2

Author Closing Comment

by:havard-fjaer
ID: 31602054
Right you are, Sir. 500 kudos to you!

A quick question, as we are on the subject: Do you know if there are any common problems associated with merging assemblies? When reflecting attributes on assemblies, for instance. Are those individual attributes still part of the merged assemblies?
0
 
LVL 8

Expert Comment

by:dericstone
ID: 24847327
Glad I could help. As far as I know the merged assemblies should work just like the original assemblies, but I don't recall specifically testing reflection on merged assemblies.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question