I want to use the same library, but with different versions of the same program. I followed the explanation in this Question, but in my case the PublicKeyToken are the same:
Is it possible to reference different version of the same assembly into a single project?
I am using the library Siemens.Ingenieering.dll. I want to use the version 15 and the version 16. I already created the extern alias for both libraries:
extern alias Siemens_Engineering_15;
extern alias Siemens_Engineering_16;
And I refer each object with the alias, for example:
public Siemens_Engineering_15::Siemens.Engineering.TiaPortal MyTiaPortal15
{
get; set;
}
public Siemens_Engineering_15::Siemens.Engineering.Project MyProject15
{
get; set;
}
This code doesn't show any errors at first. But when I execute it, it only works with the objects from the first library (V15), and it doesn't work with the other (V16). The following error shows:
System.TypeLoadException: "The type "Siemens.Engineering.Loader.IAppSupport" in the assembly "Siemens.Engineering.Contract, Version=1500.0.2601.1, Culture=neutral, PublicKeyToken=37a18b206f7724a6" could not be loaded."
This is my App.config:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Siemens.Engineering" culture ="neutral" publicKeyToken="d29ec89bac048f84" />
<codeBase version="15.0.0.0" href="Lib/Siemens.Engineering.15.dll"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Siemens.Engineering" culture ="neutral" publicKeyToken="d29ec89bac048f84" />
<codeBase version="16.0.0.0" href="Lib/Siemens.Engineering.16.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
And this warning also shows:
Severity Code Description Project File Line Suppression state Warning The conflict between "Siemens.Engineering, Version=16.0.0.0, Culture=neutral, PublicKeyToken=d29ec89bac048f84" and "Siemens.Engineering, Version=15.0.0.0, Culture=neutral, PublicKeyToken=d29ec89bac048f84" cannot be resolved. Selection of "Siemens.Engineering, Version=16.0.0.0, Culture=neutral, PublicKeyToken=d29ec89bac048f84" at random.
I already tried to create a new Class to use each library.
I think the program fails because of the same token, so it only reads one of them. But I don't know how to resolve it.
I started recently with c# language, so I would really appreciate any kind of help :)