Question

I'm trying to use ILMerge to create a single executable that uses Windows Azure SDK 2.0 including the Microsoft.WindowsAzure.ServiceRuntime.dll, which I added manually because I couldn't find any NuGET package that contains it.

I'm using the following command line on a VS2012 post-build event:

/wildcards /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /log:ILMerge.log /closed Output.exe *.dll /out:Executable.exe

However, I'm getting the following error in ILMerge.log, even though the output window reports no issues at all after building:

The assembly 'Microsoft.WindowsAzure.ServiceRuntime' was not merged in correctly. It is still listed as an external reference in the target assembly.
An exception occurred during merging:
ILMerge.Merge: The assembly 'Microsoft.WindowsAzure.ServiceRuntime' was not merged in correctly. It is still listed as an external reference in the target assembly.
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

And then the executable throws the following exception when opened:

System.Reflection.TargetInvocationException: Exception has been thrown by the 
target of an invocation. ---> System.IO.FileNotFoundException: Could not load file
or assembly 'msshrtmi, Version=2.0.0.0, Culture=neutral, publicKeyToken=31bf3856ad364e35'
or one of its dependencies.

I have also tested the same output without merging and it works fine.

What am I missing here?

Was it helpful?

Solution

It would seem like this cannot be done, or at least not how I want it done.

Microsoft.WindowsAzure.ServiceRuntime.dll seems to have a dependency on the native library msshrtmi.dll. This means that ILMerge cannot handle it, since unmanaged code cannot be merged with managed code.

According to these two questions there is a way to work around this problem, but it involves packaging the msshrtmi.dllas a resource and unpacking it when it's needed. I feel it's kinda hacky.

So I guess I'll just have to do what I should have done before: remove all references to Microsoft.WindowsAzure.ServiceRuntime.dll from the project that builds the merged, non-Azure version of my WCF service. This might involve using some IoC container and doing some heavy refactoring, which is why I was trying to avoid it at this stage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top