16

I have to use a DLL as an API in my application (C#, .NET 4.5). I can reference the DLL normaly. No error at all. But if I want to use any class of this DLL, I get the following compile error:

Error CS1705 Assembly 'Assembly_X' with identity 'Assembly_X, Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00' uses 'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=c878e80841e75d00' which has a higher version than referenced assembly 'Assembly_YY' with identity 'Assembly_YY, Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d00'

Then i checked the DLL (Assembly_X) in ILSpy. The Assembly_X has two references to Assembly_YY: One with the version 12.3.0.0 and one with the version 65535.65535.65535.65535.

I tried the "bindingRedirect" in the App.config. But since the error occures during compile time this doesn't help.

I don't have the source code of Assembly_X or Assembly_YY.

How can I use this DLL or repair it?


UPDATE

The developers of the dll finally answered my call for help. The only work around they know of is to use Visual Studio 2013 instead of Visual Studio 2015 or 2017. It seems VS 2013 is not bothered by these double reference at all.

They write, that the error is created by a encrypting tool for the dll. Thank you all for your ideas and help.

Marius
  • 369
  • 1
  • 10
  • Can you update X and Y with the actual values? It will enable us to help you. – mjwills Aug 15 '17 at 12:15
  • These are DLLs from another company and I cannot post the names of the DLLs. You will not know the DLLs, since only a few people in the world are working with them. – Marius Aug 15 '17 at 12:32
  • 2
    since the PBK is the same, you could try and fake the version of your Assembly_YY by [using ilmerge](https://stackoverflow.com/a/837536/937093). Make sure you have a backup/copy of Assembly_YY before trying this. If that doesn't work you could [try it the hard way](https://stackoverflow.com/a/34045871/937093) – Steffen Winkler Aug 15 '17 at 12:57
  • 1
    What version of the .NET Framework is the 3rd party DLL compiled against? Use https://assemblyinformation.codeplex.com/ or Telerik JustDecompile to quickly check. It might be incompatible with .net 4.5 – Andez Aug 15 '17 at 14:29
  • Good Idea. But it is the same Framwork Version. ILSpy gives me this information too [assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")] – Marius Aug 15 '17 at 15:46
  • You can consider trying Fusion logging to see if it gives any further insight: https://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx – kvr Aug 25 '17 at 22:31
  • Have you tried https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions ? – Serg Aug 26 '17 at 17:58
  • @Serg redirection only works during execution time, not during compile time. – Marius Sep 22 '17 at 09:12

3 Answers3

3

It looks like the first DLL is referencing a library which is a higher version than the other DLL you are using.

so you have 3 DLL's to consider: A, B & Bv2

Your project is referencing A & B But A references Bv2 (an updated version of B) SO when you go to use functions of A it throws an error because it finds B instead of Bv2.

Slipoch
  • 750
  • 10
  • 23
  • 1
    I do not have Bv2. I think it never existed, since the version number strange. – Marius Aug 23 '17 at 09:51
  • Yeah it is a bit odd. Maybe they did a recompile of A when they had altered a little of B and it made Bv2. But it is an odd ref. it is the limit of a 16 bit integer. I would contact the people who created the DLLs and get them to check that version. – Slipoch Aug 24 '17 at 11:35
2

The problem basically that you are referencing 'Assembly_X' which references assemblies 'Assembly_YY' versions 12.3.0.0 and 65535.65535.65535.65535 and you referenced only 'Assembly_YY' version 12.3.0.0 in your application and didn't reference 65535.65535.65535.65535

Now according to the problem explanation on Microsoft Docs, and your example which you don't have the source code for the assemblies you have to:

Add a reference to 'Assembly_YY' version 65535.65535.65535.65535 of the DLL to your application to make it compile and to enable the application to run, you can provide an application configuration file that includes a <dependentAssembly> element that uses <assemblyIdentity> and <codeBase> child elements to specify the location of version 12.3.0.0 of the DLL.

  • Thank you for the idea. I do not have this the Assembly_YY version 65535.65535.65535.65535. I think it does not exists (all other assembly of this product has "meaningful" versions). Can I somehow duplicate the Assembly_YY and change the version to 65535.65535.65535.65535? – Marius Aug 22 '17 at 08:39
  • 1
    @Marius if library not so big, you can get sources (RedGate .net Reflector, Telerik JustDecompile) and try to recompile it, if only it's worth the effort – Spawn Aug 23 '17 at 04:57
  • It is worth the effort. I will try this. (ugh, never did something like this before, this will be most interesting) – Marius Aug 23 '17 at 09:52
0

You are referencing a higher version of DLL then the one you currently have. You will need to add the reference to the higher version assembly:

'Assembly_YY, Version=65535.65535.65535.65535, Culture=neutral, PublicKeyToken=c878e80841e75d00' 

in order to solve this.

Right now you are referencing

 'Assembly_X' with identity 'Assembly_X, Version=12.3.0.0, Culture=neutral, PublicKeyToken=c878e80841e75d0

If this is a downloadable library, search for it in the nuget package manager and download it. If it's a library written by you, obtain the latest version of the library and add it to your project.

Barr J
  • 10,636
  • 1
  • 28
  • 46