Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 339
BigBoss Avatar asked Sep 10 '16 04:09

BigBoss


2 Answers

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

like image 164
BigBoss Avatar answered Nov 13 '22 02:11

BigBoss


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

like image 21
Monah Avatar answered Nov 13 '22 02:11

Monah