Vous êtes sur la page 1sur 3

signup

login

tour

help
Dismiss

AnnouncingStackOverflowDocumentation
WestartedwithQ&A.Technicaldocumentationisnext,andweneedyourhelp.
Whetheryou'reabeginneroranexperienceddeveloper,youcancontribute.

Signupandstarthelping

LearnmoreaboutDocumentation

Howtobuild/deployprojectthatrequiresmultipleversionsofthesameassembly?
Iamworkingonaprojectthatusesconflict.dllversion6.2,buttheprojectalsouseshelper.dllthatusesconflict.dllversion5.8.
Icouldinstall6.2and5.8intotheGAC,butI'ldliketohavethisprojectxcopydeployable.Ibelieve.netwillsearchfortheassembliesinthe
applicationbindirectorylikeso:\bin\conflict.dll(6.2)\bin\5.8\conflict.dll(5.8)
Butatthispoint,howdoIaddareferencetobothversionsofconflict.dllintheproject,andthenhowdoImakesuretheoldconflict.dlldeploysto
\bin\5.8?DoIcreateabuildactionoristhereanotherway?
Thanks
.net visualstudio assemblies
askedSep5'10at19:41

djmc
480

3Answers

InsupportofDarin'sanswerofcourseyouneedtobeeliminatingsuchmultiversionproblems.
Hissolutionofusingabindingredirectisagoodone+1there.Icanofferasolutionthat'llallow
youtokeepbothifabsolutelynecessary,butyou'llhavetowriteabitofcode.
Theonlyrealproblemyouhavehereisthatthetwodeployedfilenameswouldhavetobethe
sameinordertobepickedupbydefaultbytheloader.Youcouldcheatreallyhorriblyandsimply
deploythe5.8dllas Conflict.exe soitcouldsitsidebyside Conflict.dll (andnewer)and
you'dfindthatitworks.
Also,followingthelinksthroughfromDarin'sansweryoucometothistopicMSDNtopicon
probing.Basedonthecontentofthis,youcouldsimplydeploythe5.8dllinto
bin\Content\Content.dllandwhentheruntimesearchesforit,itwilllookinthissubfolder
automatically.
Howeverthatisn'tagoodsolution:)
EDITNEWSOLUTION
IfbothversionsofConflict.dllarealreadysigned,haveyouactuallytrieddeployingoneofthe
versionswithaslightlydifferentname?I'vejustsetupawinformsappwithtwoassembly
referencestodifferentversionsofthesame(signed)assembly.Thiscausesacoupleof
problemswiththebuild,becausethelastreferencedversionwillbedeployedtothebinfolder,
andtheotheronewillnot(soyouhavetomanuallycopyinbothrenamingoneofthem
accordingly).ThenItryrunningtheapp,whichdisplaysamessageboxcontainingtwoconstant
stringsonefromeachversionoftheassembly.Itworksabsolutelyfine.
Downloadademoofthisheredon'tbuildit(otherwiseyouhavetodothefilerenaming)just
opentheformsapp'sbin\debugfolderandruntheexe.
ClassLibrary1.dllandClassLibary1vanything.dllarev1.0.0.0andv2.0.0.0ofanassemblywith
otherwisethesamenameandpublickey.Despitethefactthatclasslibrary1vanything.dllhasthe
wrongfilename,itstillworks(probablybecauseitissigned).
Intheapp.configIdidputinacodebasehint,andthoughtthatwaswhyitworked(originallyI
deployeditasadifferentfilename),butthenIcommenteditoutanditstillworked.Thecodebase
isprobablymostusefulinsteadwhentheassemblyhastobedeployedtoasubfolderor
completelydifferentlocation.
ORIGINALTEXT
I'vetriedtogetthesecondoftheoptionsmentionedinthissupportarticlefromMStowork,butit
doesn'tseemtowantto.
Thereisnodoubtsomecleverwaytodoitoutofthebox,butsinceI'mnotcleverenoughtohave
foundit(yet),Iwouldinsteadembellishandusethethirdoftheoptionsdisplayedinthe
aforementionedsupporttopicandhookintothe AssemblyResolve eventoftheappdomain.
Ifyouaddyourownconfiguration(probablyjustinappSettingsreally)forthefullnameofthe
assemblytobeboundtoadifferentfilename,theninyourAssemblyResolveeventhandleryou
canconsultthenameoftheassemblythatistobeloadedtoseeifit'sinyourconfiguration.Ifitis,
grabholdofthelocationanduseAssembly.LoadFromtoloadit.
Thus,onceyouhavesomethinglikethisinplace,yousimplyaddanentryfortheConflictv5.8

19

assemblynameintherealongwiththefilenamethattheappshoulduse.
Idon'tknowwhattypeofappitisthatyou'redeployingbutinwinforms,consoleappsand
services AppDomain.CurrentDomain.BaseDirectory willbeequaltothebinfolderandyoucanjoin
thatwiththefilenameyouwanttoload.Websitesarealittletrickier.
Shouldworkatreat.
editedSep6'10at8:46

answeredSep5'10at21:32

AndrasZoltan
30.5k

75

135

Thiscouldhelpmeforthisweekend.Greatanswer..Iwonthaveaccesstothesourcecodetorecompile

helper.dlltillaboutmidweeknextweeksothishopefullywillkeepmeproductive.Thanksalot! djmc
Sep5'10at21:42
@djmcwellIhopeyoumanagetogetsometractionwiththisinplace AndrasZoltan Sep5'10at22:08
@djmcjustincaseyouhaven'tnoticedIupdatedmyanswerwithademothatmighthelpyououthere.

AndrasZoltanSep8'10at7:56
thankyousomuch!itworked.Renamingthefileallowsittobeaddedtovisualstudio,andstillloadstheold

versionoftheassembly. djmc Sep9'10at20:35


Thanksfortakingthetimetofigurethisout.Ireallyappreciateit. djmc Sep9'10at20:36

Aftermanyhoursofsearchingandcursing,Ifoundasolutionthatworksandiseasyandreliable
toimplement.
Theproblemlikealltheotheranswershavepointedoutisthatallofthefollowingmustbe
satisfied:
1.BothversionsoftheDLLmusthavethesamename,otherwisetheruntimewillcomplainthat
thenamedoesn'tmatchthemanifest.
2.Theruntimehastobeabletofindbothassembliesinthesearchpath.
3.Aversionredirectisnotpossiblebecauseofbreakingchanges.
4.AppDomain.ResolveAssemblynevergetscalledinthisexamplebecausetheassemblyhas
beenloadedoncealready.
Thesolutionisthefollowing,insteps:
1.Createadirectoryinyoursolutiondirectorysuchas lib\ withthishierarchy:
lib\Conflict\v1\Conflict.dll
lib\Conflict\v2\Conflict.dll
2.Addthefollowingtoyour app/web.config :
<runtime>
<assemblyBindingxmlns="urn:schemasmicrosoftcom:asm.v1">
<dependentAssembly>
<assemblyIdentityname="Conflict"publicKeyToken="111111111111"/>
<codeBaseversion="1.0.0.0"href="bin\Conflict\v1\Conflict.dll"/>
<codeBaseversion="2.0.0.0"href="bin\Conflict\v2\Conflict.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

1.Addapostbuildeventwithan xcopy :
xcopy$(SolutionDir)\lib$(TargetDir)/Y/S
2.Buildoncesothatthefilesarecopied.Clickon"Project>Showallfiles".Rightclickon
bin\Conflict anddo IncludeinProject (savesyoufromdoingitincode).Thisis
necessarytohavethefilesdeployedifyoupackageawebapplication.
Done!
editedJun13'12at10:33

answeredJun7'12at17:12

georgiosd
1,649

22

Sowhatdoyouaddtoweb.configinstep2? Aaronontheweb Jun13'12at0:56


XMLdidn'tshowupwith<code>,needed<pre> georgiosd Jun13'12at10:34

Ibelieve.netwillsearchfortheassembliesintheapplicationbindirectorylikeso:
\bin\conflict.dll(6.2)\bin\5.8\conflict.dll(5.8)
No,thisiswrong.Iwouldsuggestyoureadingthisarticletolearnmoreaboutwhatheuristics
doestheCLRuseforprobing.
Thisbeingsaid,youcannothavetwodifferentversionsofthesameassemblyloadedinthesame
applicationdomainyoucanloaddifferentversionsofthesameassemblyintothesame
applicationdomainbutitisconsideredbadpracticeandshouldbeavoided.Inyourcasethis
meansthatyouwillhavetochoosewhichversionoftheconflictingassemblyyouwanttouse.
Youhaveacoupleofchoices:
1.Recompile helper.dll tousethelatestversionof conflict.dll (Iwilldefinetelygowiththis
oneifIhavethesourcecodefor helper.dll ).

38

2.Choosewhichversionof conflict.dll youwantandapplya <bindingRedirect> inyour


configfile.Forexampleifyouwanttousethelatestversion:
<runtime>
<assemblyBindingxmlns="urn:schemasmicrosoftcom:asm.v1">
<dependentAssembly>
<assemblyIdentityname="conflict"
publicKeyToken="xxxxxxxxx"
culture="neutral"/>
<bindingRedirectoldVersion="5.8.0.0"
newVersion="6.2.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

ThiswilleffectivelyinstructtheCLRtoloadversion6.2of conflict.dll whenittriestoresolve


referencesfor helper.dll .Notethatifthetwoversionsarestronglysignedwithdifferentkeys
thistechniquewon'twork.Obviouslyas helper.dll hasbeencompiledagainstversion5.8ifyou
haveanydifferences(missingmethods,differentmethodsignatures)youwillgetaruntime
exceptionwhentryingtocallaconflictingmethodsodothisonlyifyouareabsolutelysurewhat
youaredoing.
Conclusion:nomatterwhichpathyoudecidetotake,youwillhaveto xcopy inthebinfoldera
singleversionofthe conflict.dll .
editedSep5'10at21:00

answeredSep5'10at20:32

DarinDimitrov
678k
2345

151

2445

1 @darinsorrybut'youcannothavetwodifferentversionsofthesameassemblyloadedinthesame
applicationdomain'isincorrect.Notonlycanyouhavetwoloadedatthesametime(andusethem
independently)youcanalsoloadthesameassemblymorethanonceintoanapplicationdomainanduse
themindependently.Tryusing Assembly.LoadFrom toloadanidenticalassemblyfromtwodifferent
locationsthencallthe AppDomain.CurrentDomain.GetAssemblies() AndrasZoltanSep5'10at20:50
1 @Andras,youarecorrect,Iwillupdatemyposttoreflectyourcomment.Thanksforpointingthisout.
DarinDimitrov Sep5'10at20:59
@Darin+1inanycaseforofferingasolutionthat'llalsohelpgetthehouseinorder:) AndrasZoltan Sep

5'10at21:35
Iseewhythisisabadpractice,IjusthadaruntimeexceptiontryingtouseabindingRedirectbecause

obviouslytheinterfaceswithintheassemblieshavechangedandhelper.dllisfreakingout. djmc Sep5


'10at21:35
IwillseeifIcanrecompilethesourcecode.Thankyouverymuchforyouranswer..you'vehelpedme

understandwhat'sgoingonherebetter. djmc Sep5'10at21:36

Vous aimerez peut-être aussi