Why my system is trying to load a type from an invalid version of the assembly?
Asked Answered
P

4

8

I'm working on an old system that is using NHibernate 3 and spring for DI, I have to do some refactor on this solution. some of the projects of the solution was using NHibernate 1.2, I changed them to NHibernate 3. Now the only version of the NHibernate that is used in entire solution is 3.

Now the problem is when I try to load any of the web services in the solution, system try to load a type from NHibernate 1.2, I have tested published project in another system and it is working just fine, and it should be a problem with my system, it just give me: Could not load type 'NHibernate.Event.ListenerType' from assembly 'NHibernate, Version=1.2.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'.

Can anyone help me find out why CLR is trying to load a type from an unreferenced assembly?

Pathe answered 10/9, 2016 at 4:52 Comment(15)
Do you refer to any other libraries that use NHibernate 1.2?Cultivar
@JonSkeet no jon I double checked all my libraries, none of them refered to NHibernate 1.2, and beside that it work perfectly fin in other systemsPathe
Any configuration differences between environments? Something like BindingRedirect in App.config/Web.config?Elector
@Corwin no I don't think so, I just published my web site with web.config and DLLs and installed them on my local IIS and remote IIS on my work network, it work completely as expected in other systems but not on my dev PCPathe
Do you have any obsolete assemblies left in the local application installation folder left from a previous version?Desiccator
@OskarBerggren No, I rebuild solution, cleared ASP.NET temporary folder, published application and installed to a different site in IIS, nothing worked. I also think problem is with .NET caching, but I don't know what other location I should look atPathe
This article covers the various ways that bindings can be redirected at the app, machine and publisher level. You'll need to check that none of them have been employed on your machine.Abundance
@Abundance Unfortunately none of them apply to me!!Pathe
@Pathe Try to remove that assembly from global assmebly cache: gacutil –u NHibernateAmii
Have you had a look at your binding log, it may offer more information as to where the old version is coming from: msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspxCoinsure
@Phaeze I tried to use 'fuslogvw', I run it with administrative priviledge and it show nothing at allPathe
If you are using spring do you use xml configuration files or do you fill your container in code only?Vitals
btw if it is a compile time issue on your system you can get a warning while compiling (rebuild or clean first). Scan the output window for mentioning of conflicting versions.Vitals
@Uwe I use XML configuration file, and I have no warning on my system, I already cleaned ASP.NET temporary files, my project's output and object file a dozen of times. and beside I said my project output work totally as expected on another system on my workplace, so I think problem is not on my output but on my system. today I compiled the solution on another PC and result was as expected, so there is a problem on my systemPathe
If I remember spring correctly you can specify an explicit dll to instantiate objects from. Did you check that it is not coded in the XML Files? That would not show up anywhere and is hard to find. It would work on other systems if it cannot find the correct version and uses a "fallback". Maybe scan them?Vitals
P
6

Thanks to every one that tried to help me, but I found the response.

I have .NET Reflector on my system and once upon a time, I used that to reflect NHibernate on my system and it was version 1.2.1.4000, it created a copy of my DLL in its cache and it was preferred in load order. I deleted the cache and now everything is working as expected

Pathe answered 18/9, 2016 at 8:30 Comment(2)
how you deleted the cache? I have similar problemArmyworm
@mah just deleted "C:\ProgramData\Red Gate\.NET Reflector\DevPath", I used "Assembly.LoadFile" to load the file that I wanted and checked address of returned assembly and find the pathPathe
A
2

Same problem happens with me many times but with different dlls

I will share what steps I followed in order to get rid from this problem

  1. Delete Debug and Release folder
  2. Delete obj folder
  3. Unload the project and load it again ( right click on the project and click on Unload and then right click and click Load Project)
  4. Right click on the Solution and Click Clean Solution
  5. Right Click on the Solution and Click Rebuild Solution

I hope this will work with you

Armyworm answered 17/9, 2016 at 21:0 Comment(1)
ty for the answer, but I create a new solution on my system, use same DLLs and same problem happend. I think something is wrong on my systemPathe
A
0

You can try to remove that assembly from global assembly cache:

At the command prompt, type the following command: gacutil –u NHibernate

Gacutil.exe is a part of a Windows SDK suite. On my computer it's located in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64

Amii answered 13/9, 2016 at 11:22 Comment(1)
ty for your answer but I already checked that and NHibernate is not in my GACPathe
M
0

Please check if you have a <bindingRedirect> tag in your App.config/Web.config file. I faced a similar problem in an ASP.NET MVC project with Newtonsoft.Json.dll which i fixed by updating the oldVersion and newVersion attributes of the <bindingRedirect>tag. https://noodlearoundnet.blogspot.in/2016/09/newtonsoft-json-dll-version-mismatch.html

Maes answered 13/9, 2016 at 12:49 Comment(1)
ty for the answer but I have no redirection either implicit or automatic for NHibernate in any of the projects in my solution.Pathe

© 2022 - 2024 — McMap. All rights reserved.