-1

Lets say i have the below assembly files reference in my solution:

  1. a.dll
  2. b.dll
  3. c.dll
  4. Main_43.dll
  5. a_40.dll
  6. b_40.dll
  7. c_40.dll
  8. Main_40.dll

My console application used to load only the first 4 before as the client used Main_43.dll which internally used a,b and c dll files. Now, i have to add a new client to my console application that will be using Main_40.dll which is the older version of Main_43.dll(I have to use the old version. No option to upgrade). I have renamed a, b and c dll files for this version by suffixing '_40' as seen above.

I have referenced all of them in my console application. How can i tell the application to use Main_43 or Main_40 based on the parameter i pass to console app and how can i be sure that Main_40 will reference a,b and c dlls files that are meant for v40 and vice versa?

Also, what is the best practice to call methods in my program that might me in both dlls? Should i use the full reference name such as:

Main_40.Export exportData = new Main_40.Export(); 

or is there a better way?

The assembly files are strong named

Aswin Francis
  • 87
  • 1
  • 13
  • OP, unless all the different assemblies are _strong named_ you can't –  Feb 16 '18 at 08:08
  • @MickyD The assembly files are strong named. 'sn -vf a.dll' said it is valid. So did the rest. Public key is same though – Aswin Francis Feb 16 '18 at 08:56
  • Have you read [Side-by-Side Execution in the .NET Framework](https://docs.microsoft.com/en-us/dotnet/framework/deployment/side-by-side-execution), [Assemblies and Side-by-Side Execution](https://docs.microsoft.com/en-us/dotnet/framework/app-domains/assemblies-and-side-by-side-execution), and [Guidelines for Creating Components for Side-by-Side Execution](https://docs.microsoft.com/en-us/dotnet/framework/deployment/guidelines-for-creating-components-for-side-by-side-execution)? Do note these are for .NET Framework - there doesn't seem to be any docs on whether this is possible in .NET Core. – NightOwl888 Feb 16 '18 at 09:13
  • @NightOwl888 these are assembly referenced in the project.I cannot register these dlls in the GAC.They are all in the folder with the exe. – Aswin Francis Feb 16 '18 at 10:08
  • Related: [Using 2 different versions of the same dll?](https://stackoverflow.com/questions/42715564/using-2-different-versions-of-the-same-dll) – NightOwl888 Feb 16 '18 at 10:17
  • @NightOwl888 ok i created a folder libs under which i have 2 folders v40 and v43 and i have put the dlls 1 to 4 in v43 and the rest in v40. I referenced just the Main_40.dll and Main_43.dll in the solution as that is enough for my purpose and those assemblies internally calls a,b and c dll. Now when i build the solution a,b and c dll is also getting copied to the path where exe exists. I think if i can avoid that and make sure the main dlls use what is in its folder it should work. Do you know if that is possible? – Aswin Francis Feb 16 '18 at 10:54
  • Looks like you can use the [Copy Local](https://learn.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items#reference) property of the reference in Visual Studio. – NightOwl888 Feb 16 '18 at 11:02
  • @NightOwl888 thank you! that stopped copying the dll to the exe folder. Now the problem is when i call main_40.dll method, it tries to reference v43 version of a.dll instead of v40 version as it should be done in an ideal condition. Any idea what might be causing it to reference the latest version internally? – Aswin Francis Feb 16 '18 at 11:17
  • I think i will try to create instance of the class in the code as required – Aswin Francis Feb 16 '18 at 11:24

1 Answers1

0

So this is how i went about with the change. I created a folder 'libs' under which i have 2 folders v40 and v43 and i have put the dlls 1 to 4 in v43 and the rest in v40 and then when my class is called, i load the dll dynamically. I also made sure that 'Copy always' is set so that dlls are always moved to the folder during build.

Now when i hit the client constructor that will be using v40 dll, i load the assembly path and then create an instance of main_40

    protected const string mxMainDLLPath = @"libs\v40\Main_40.dll";
    dynamic mainObj = null;
    public ClientClass()
    {
        Assembly assembly = Assembly.LoadFrom(mxMainDLLPath );
        Type T = assembly.GetType("Main_40.Export");
        mainObj = Activator.CreateInstance(T);
    }

Now to call any method in Main_40.dll, i can do mainObj.Export().

Thanks to @NightOwl888 for all the help.

Aswin Francis
  • 87
  • 1
  • 13