.NET type definitions in federated assemblies (ILMerge)

I am integrating several .NET assemblies using ILMerge, including some third-party assemblies. Since this happened, I experienced several errors, which all boil down to the fact that type definitions are tied to the assembly in which they are defined.

A simple example is to define the log4net configuration section in my App.config application. It uses type = "log4net.Config.Log4NetConfigurationSectionHandler, log4net", which will not work because the log4net assembly does not exist once it has been merged with my combined assembly. However, not a big deal, I change the assembly name to my combined assembly, and it works fine.

A slightly more complex example is binary serialized types. My system uses binary serialization to send specific objects between processes. All serializable objects are defined in the general assembly, which are all other references to projects. I used the default binary serialization, but it started crashing when deserializing objects with an error, stating that it could not find the merged assembly that serialized the object. Again, it doesn’t matter, I implemented a custom SerializationBinder that looks for a type in any loaded assembly, not just one.

The previous example got more complicated when the serialized type referred to other serializable types. I continued to face more and more problems that were becoming increasingly difficult to cope with.

What I'm trying to understand is that a system like .NET and ILMerge do not work well together. Does anyone have any experience with how they solved this problem? Is it possible to tell .NET runtime that I don't care what assembly says it should be, just find it somewhere?

NOTE. Please do not answer the question why I am assembling assemblies, this is not a question of this question.

+6
types ilmerge
source share
3 answers

Yes, there is a solution to this problem: assembly of modules instead of assemblies!

Compilers for .net have an option (/ target: module for C # and VB) that builds a module instead of a build. Then several modules can be passed to the compiler and used to build the final assembly.

Of course, all this assumes that you have a source for third-party assemblies. If you cannot do this, is it possible that a version of the third version of the third party can be purchased from a third party?

If this does not work, you still have the last option. Obviously, you are already parsing a third-party build in IL. Extract the assembly information from this IL file and use "ilasm / dll" to create the .net module, which you can now use just like any other .netmodule!

Using modules instead of assemblies, you should not have more problems with the assembly.

True, we solved your problem with ILMerge without using ILMerge anymore, but isn't this the best solution?

Hope this works for you, here are some handy links:
. netmodule instead of assembly
ILASM with .netmodules

(And here I thought that my experience with .netmodules would never be useful to anyone!)

+4
source share

A few years after the question, I ran into the same problem and found a solution. You can add [assembly: log4net.Config.XmlConfigurator(ConfigFile = "logging.config", Watch = true)] to the AssemblyInfo.cs file, and this will work when combining the log4net assembly.

0
source share

Welcome to the dangers of lines and (physical location) lines in code.

All of these tools have similar problems, and they are better smart, because many developers and developers of runtime functions, such as binding and serialization, do not actually consider this, but they probably pushed ILMerge as a smart tool. He is so smart that he can't even trim types.

Please note that version control also comes into play here, and the configuration, * and stars in the eyes, and the independence of the versions from Redmond does not help either.

You will surely worry about battles with a third party. And believe me, I know that you need merging, as some pathetic small types can take ages for MS JIT to play in large applications (and no, I don’t want NGEN or optimized 3.5SP1 loading to be even slower, than before due to System.Core or sky-forbid WPF bloat).

The best option, imho, at least on a large scale, is to get a decent commercial tool that scans and processes this (i.e. from existing pain and obfuscation). Ultimately, you can exit the existing IL code if you don't have any sources.

[Then came the string invention INotifyPropertyChanged, which so solved the problem of global warming - developed by Inventor Casio-Calc]

-2
source share

All Articles