Skip to content

Instantly share code, notes, and snippets.

@maciakl
Last active December 19, 2017 10:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maciakl/7018396 to your computer and use it in GitHub Desktop.
Save maciakl/7018396 to your computer and use it in GitHub Desktop.
ILMerge unresolved assemblies errors

ILMerge Unresolved Assembly Errors

Running Win 7 and Visual Studio Express 2013 for Desktop. If you are getting error messages like this:

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.GetMethodToken(Method m)
  at System.Compiler.Ir2md.VisitMethodCall(MethodCall call)
  at System.Compiler.Ir2md.VisitBranch(Branch branch)
  at System.Compiler.Ir2md.VisitBlock(Block block)
  at System.Compiler.Ir2md.VisitBlock(Block block)
  at System.Compiler.Ir2md.VisitMethodBody(Method method)
  at System.Compiler.Ir2md.VisitMethod(Method method)
  at System.Compiler.Ir2md.VisitClass(Class Class)
  at System.Compiler.Ir2md.VisitModule(Module module)
  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)
  at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
  at ILMerging.ILMerge.Merge()
  at ILMerging.ILMerge.Main(String[] args)

There is an easy solution. You simply need to add /targetplatform:v4,[dotnet-path] parameter to your ILMerge build command. For me the framework path is:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

Tyhe full merge command should look something like this:

ilmerge /targetplatform:v4,"C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:"c.exe" "a.exe" "b.dll"

This should resolve the issue.

@mattrasband
Copy link

This got me most of the way there, but I had to quote the whole /targetplatform section for it to work in my case, not really to sure why though:

ilmerge /targetplatform:"v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319" /out:"c.exe" "a.exe" "b.dll"

@prateek1108
Copy link

hi
i am also trying these same command and getting an error exception occurred during merging........
my project include version 4.5 of .netframe work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment