I have situation something like this:
1 Solution that contains 3 projects:
- 1 console application which references these 2 other elastic related projects
- 1 elastic search v1 project, which contains Nest and ElasticSearch.Net v1 libraries to do searches to our old elastic 1.4 cluster
- 1 elastic search v5 project, which contains Nest and ElasticSearch.Net v5 libraries to do searches to our new elastic 5.4 cluster
Nest library is 1 Nuget package and you are supposed to use right version for your elastic cluster. It uses internally ElasticSearch.Net library. Also Newtonsoft.Json is conflicting between these library versions.
Most answers to similar questions are related assembly redirect but in this case it's not possible because versions are not compatible.
I tried to use Fody/Costura (https://github.com/Fody/Costura) to embed elastic related dlls into my elastic v1 and v5 libraries to avoid conflicts. Embedding itself works fine meaning that those dlls are not copied to bin-folder.
I didn't try ILMerge yet but my understanding is that it's similar to Costura.
public void Test1()
{
var es1Helper = new MyElasticSearchV1RelatedProject.SearchHelper();
es1Helper.TestSearch();
var es5Helper = new MyElasticSearchV5RelatedProject.SearchHelper();
es5Helper.TestSearch();
}
public void Test2()
{
var es5Helper = new MyElasticSearchV5RelatedProject.SearchHelper();
es5Helper.TestSearch();
var es1Helper = new MyElasticSearchV1RelatedProject.SearchHelper();
es1Helper.TestSearch();
}
But Test1 fails
System.TypeLoadException: 'Could not load type 'Nest.Indices' from assembly 'Nest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.'
And Test2 fails
System.TypeLoadException: 'Could not load type 'Elasticsearch.Net.ConnectionPool.IConnectionPool' from assembly 'Elasticsearch.Net, Version=5.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d'.'
It looks like that depending on the order, other dll versions are loaded and the other library project tries to use them as well.
Is there any way to use both versions on the same project?