2

I have two DLLs with separate code inside them, but with the same NAME and same VERSION. Neither of these can be changed. They are in two separate C# projects, which do not reference each other, but are instead class libraries loaded within the same Console app. I've got a small diagram listed below.

Flow chart

When running the app it seems to take one of these in compilation, seen in the output directory, and thus throws a reflective exception trying to call code from the other DLL in the code of the second class library. In Visual Studio, everything seems fine in the IDE - and references the contents of each DLL as different per library project.

I was wondering if there was any way to get this working without editing the DLLs at all, like a build step that I can set up easily, to ensure these DLLs aren't confused with each other, so to speak.

To clarify, many other questions on this platform question have different versions of the same named DLL. In this, identifiers like the name and version are identical - what's not, is the code inside each. I know this should never happen unless you're doing something really hacky.

Thanks in advance!

FeroxFoxxo
  • 576
  • 1
  • 5
  • 18
  • 1
    You will need to learn about [Loading DLLs into a separate AppDomain](https://stackoverflow.com/questions/88717/loading-dlls-into-a-separate-appdomain) – John Wu Nov 25 '22 at 01:34
  • @JohnWu AppDomains seem to be obsolete in .Net Core (at least starting with NET 6). – FeroxFoxxo Nov 25 '22 at 02:09
  • In that case I have no clue how to do it. I'm upvoting your question. – John Wu Nov 25 '22 at 03:04
  • If you're looking for some magic HintPath or something I'm pretty sure you're are not going to find it. You're breaking all the rules in the book *because its what you need to do*. This should never happen, why? Two DLLs same version, same name BUT completely different code?? An upvote for your certified [so] drawing skills tho :) – Jeremy Thompson Nov 25 '22 at 04:53
  • For .NET (Core) you have assembly load contexts: [Managed assembly loading algorithm](https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/loading-managed) – Paulo Morgado Nov 25 '22 at 11:02
  • Are these projects in the same solution, or are you referencing DLLs directly? – Paulo Morgado Nov 25 '22 at 11:04
  • @PauloMorgado Same solution, different projects as class libraries, both projects are loaded by a Console App in the same solution, with each project having a Reference Hint Path to the dependency. – FeroxFoxxo Nov 26 '22 at 01:31
  • You can't do that. The project system will only pick the lady one. – Paulo Morgado Nov 26 '22 at 11:26
  • And you can't deploy that, either. – Paulo Morgado Nov 26 '22 at 11:27
  • You'd have to have the DLLs w/ same name deploy into subfolders, and then pick that at runtime with AppDomains/AssemblyLoadContexts. But you're really fighting an uphill battle to make that work. – Jason Malinowski Nov 28 '22 at 21:56

0 Answers0