Posts
208
Comments
1144
Trackbacks
51
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
Comments
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Sarah Vessels
6/2/2010 9:56 AM
Thanks for posting this, it was just in time--I hit this problem just yesterday! Your suggestion of using the /lib parameter with ILMerge worked... sort of. Now I get " Unresolved assembly reference not allowed: Microsoft.VisualStudio.QualityTools.UnitTestFramework". Sigh, more Google searches ahead.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Sarah Vessels
6/2/2010 10:00 AM
Looks like adding /lib:"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies" fixed the UnitTestFramework unresolved assembly reference.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Steve
6/2/2010 10:08 AM
@Sarah - Keep in mind that assembly is in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies directory so you'd have to explicitly include that as well.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Steve
6/2/2010 10:09 AM
Looks like you already found your answer. :)
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Maik
5/13/2011 6:10 AM
Thx a bunch, ran into this problem today! :)
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Neveen
9/25/2012 1:58 AM
Thanks A lot
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Thanks
2/23/2013 9:49 PM
Thank you! This is exactly what I was needing.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Dillon
3/13/2013 3:50 AM
http://stackoverflow.com/questions/2961357/using-ilmerge-with-net-4-libraries/2962378#2962378

This link to stackoverflow will supply some answers as well for anyone still having issues. Setting:
/targetplatform:v4,<path to your v4 framework directory> instead of
/targetplatform:v4 /lib:<path to your v4 framework directory>

Has solved a lot of V4 issues.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
ccman32
6/14/2013 3:32 PM
Thanks, this helped me alot :)
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
ccman32
6/14/2013 3:36 PM
Just one thing: The executable instantly crashes after using ILMerge now... :(
Gravatar
# re: ILMerge (StackOverflowException)
Ram Babu S
12/9/2013 6:30 AM
Process is terminated due to StackOverflowException.

I have .NET 4.5 but I cannot find "Framework" folder in "C:\Program Files\Microsoft.NET"

I tried both /lib path and .config file. but it says ..
Process is terminated due to StackOverflowException.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Phil
6/8/2015 6:01 AM
Very useful, thanks for posting this.
Gravatar
# re: ILMerge - Unresolved assembly reference not allowed: System.Core
Employee
7/9/2015 8:28 AM
Thank you, came across the same problem today!

Post Comment

Title *
Name *
Email
Comment *  
Verification

View Steve Michelotti's profile on LinkedIn

profile for Steve Michelotti at Stack Overflow, Q&A for professional and enthusiast programmers




Google My Blog

Tag Cloud