0

I get this error message while compiling:

Assembly 'MyFramework [...]' uses 'System.Web.Extensions, Version=3.5.0.0 [...]' which has a higher version than referenced assembly 'System.Web.Extensions, Version=1.0.61025.0 [...]'

MyProject refers both System.Web.Extensions 1.0 AND project 'MyFramework', the latter in turn refers web extension 3.5. Both references are Copy local = false, Specific version = true.

The error occurs in MyProject (not in MyFramework). What is wrong here?

I understand that two versions of the same assembly cannot coexsist on the same location, this is why copy local is false.

(I know the setup is lame, it's a huge legacy application, can't just refactor anything.)

UPDATE: there must be something with my project. I created a sample project (for 2.0, referring web extensions 1.0) that uses another sample project(fwk 3.5, web extensions 3.5) an compiles all right. (The way I expected.) So I basically modelled the situation and could not reproduce the problem. The question has changed to:

What may cause the above behaviour? Technically, is there anything wrong in refering two versions of the same strong-named assembly?

UPDATE 2: see accepted answer comments for the root cause. ("Exposed types.") Still need to find the way to solve it.

Dercsár
  • 1,636
  • 2
  • 14
  • 26
  • Possible duplicate of [Need a way to reference 2 different versions of the same 3rd party DLL](https://stackoverflow.com/questions/11550981/need-a-way-to-reference-2-different-versions-of-the-same-3rd-party-dll) – Orace Nov 20 '19 at 11:16

2 Answers2

1

You have to use extern alias to reference two distinct versions of the same assembly.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • That would be the solution, if wanted to refer two versions of the same assembly from a single project. Thanks for noting, but in my case, i have a project, that refers an assembly(v1) and another project, that in turns refers the same assembly(v3.5). This could be all right however, I modelled this case and compiles well. Need help to find out what can cause the error. – Dercsár Jan 31 '11 at 18:02
  • Well, your MyFramework assembly is exposing types from System.Web.Assemblies in its public classes. They are 3.5 types, that conflicts with the 1.0 assembly reference. If you want this trouble-free without extern alias then you'll need to avoid exposing those types. – Hans Passant Jan 31 '11 at 18:14
  • That is the key. (Exposed types.) VS offers a resolution by creating the necessary binding redirection, but it does not seem to work. Need to somehow do it manually. Marked as answer for the idea. Thanks. – Dercsár Jan 31 '11 at 19:16
0

You need to add a <bindingRedirect> in App.config.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • This will only work, however, if either the project he's compiling really *could* reference 3.5, or if the other project really could reference 1.0. This won't work if they're genuinely incompatible. – Adam Robinson Jan 31 '11 at 17:02