jeudi 10 avril 2014

.net - comportement étrange Assembly.Load - Stack Overflow


I have "Microsoft.Web.Services2.dll" V2.0.3.0 in my GAC of two machines.


I am running this line in both of them:


Assembly.Load("Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

(note the version is 2.0.0.0 and not 2.0.3.0)


On one machine this fails (as I would expect). In another it works and the loaded dll is 2.0.3.0. Actually on this machine every version lower than 3 works (and loads 3).


How can you explain this?




Maybe you have Microsoft.Web.Services2.dll in your bin folder. Check the assembly location:


var assembly = Assembly.Load("XXX");
Console.WriteLine(assembly.Location);



This might be related to loading a "Specific Version" flag. If you check the assembly properties in References folder in Visual Studio, it shows a "Specific Version" property which I think specifies whether to link to specific version of an assembly or not (default is false). By default, it will link to any specific OR newer version of the assembly and that whats happening here I guess.


So there might be some option in Load method itself that specifies whether to load the specific version ONLY or fall back to a more recent one if specific is not found.




answer is here:


http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/13a95aa8-4dc3-4b91-af19-c460c6e1fca6?prof=required



I have "Microsoft.Web.Services2.dll" V2.0.3.0 in my GAC of two machines.


I am running this line in both of them:


Assembly.Load("Microsoft.Web.Services2, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

(note the version is 2.0.0.0 and not 2.0.3.0)


On one machine this fails (as I would expect). In another it works and the loaded dll is 2.0.3.0. Actually on this machine every version lower than 3 works (and loads 3).


How can you explain this?



Maybe you have Microsoft.Web.Services2.dll in your bin folder. Check the assembly location:


var assembly = Assembly.Load("XXX");
Console.WriteLine(assembly.Location);


This might be related to loading a "Specific Version" flag. If you check the assembly properties in References folder in Visual Studio, it shows a "Specific Version" property which I think specifies whether to link to specific version of an assembly or not (default is false). By default, it will link to any specific OR newer version of the assembly and that whats happening here I guess.


So there might be some option in Load method itself that specifies whether to load the specific version ONLY or fall back to a more recent one if specific is not found.


0 commentaires:

Enregistrer un commentaire