ILMerge - Unresolved assembly reference not allowed: System.Core

ILMerge - Unresolved assembly reference not allowed: System.Core

ILMerge is a utility which allows you the merge multiple .NET assemblies into a single binary assembly more for convenient distribution. Recently we ran into problems when attempting to use ILMerge on a .NET 4 project. We received the error message:

An exception occurred during merging:
Unresolved assembly reference not allowed: System.Core.
    at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
    at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
    at System.Compiler.Ir2md.VisitReferencedType(TypeNode type)
    at System.Compiler.Ir2md.GetMemberRefIndex(Member m)
    at System.Compiler.Ir2md.PopulateCustomAttributeTable()
    at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
    at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
    at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
    at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
    at ILMerging.ILMerge.Merge()
    at ILMerging.ILMerge.Main(String[] args)

It turns out that this issue is caused by ILMerge.exe not being able to find the .NET 4 framework by default. The answer was ultimately found here. You either have to use the /lib option to point to your .NET 4 framework directory (e.g., “C:\Windows\Microsoft.NET\Framework\v4.0.30319” or “C:\Windows\Microsoft.NET\Framework64\v4.0.30319”) or just use an ILMerge.exe.config file that looks like this:

1: <configuration>

2: <startup useLegacyV2RuntimeActivationPolicy="true">

3: <requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>

4: </startup>

5: </configuration>

This was able to successfully resolve my issue.

posted on Wednesday, June 2, 2010 6:51 AM Print

This article is part of the GWB Archives. Original Author: Steve Michelotti

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.