ILMerge Issues

Jul 6, 2015 at 8:14 AM
Like some other posters, I am having trouble using NetOffice with ILMerge.

I use NetOffice with Excel, through both add-ins and stand-alone apps. My apps or add-ins will run fine before merging, but after merging I will get "Factory has not been initialized with NetOffice libraries" exceptions in different places. Some references to classes in ExcelApi.dll or the other NetOffice libraries will work fine, but some will not.

The current example that I'm stuck on is with the ExcelApi.Application.AddIns property. I can get a reference to an AddIn object with an expression like
AddIn a = app.AddIns.Add(filepath); 
but I cannot query the contents of an AddIns collection with an expression like
foreach (AddIn a in app.Addins) do stuff;
This will give me the "Factory not initialized" exception, but only if I've use ILMerge.

I've tried explicitly calling
but that does not change anything.

I've looked at the source code for the Core/Factory object and my guess is that it has to do with the factory loading assemblies by name. Is this correct? How can I get around this?
Jul 6, 2015 at 6:07 PM
*first what i have to say:

its first time for me to face an ILMerge problem(Like some other posters? realy???)

i need 1-2 day(s) to reproduce the problem because i have no experience with ILMerge - at all.

its a kind of magic. my current idea is ILMerge works in another AppDomain and the NetOffice enumerators are not ready to handle this for self-initializing. in other words: your Intialize() call is in your appdomain works well but ILMerge works in his own AppDomain and the first enumerator doesnt works because NetOffice miss the self-initializing check here. as possible hot fix and error trace for me: please try to call a foo[!] Application method or property before . (the methods and properties initialize the NetOffice.Core in his AppDomain but may the self-check is missing for enumerators possible bug)

(nice to know: did you use Office from multiple threads?)