For complete separation/decoupling, I've implemented a DAL in an assebly that is simply being copied over via post-build event to the website BIN folder. The website then on Application Start loads that assembly via System.Reflection.Assembly.LoadFile
. Again, using reflection, I construct a couple of instances from classes in that assembly. I then store a reference to these instances in the session (HttpContext.Current.Items)
Later, when I try to get the object stored in the session, I am not able to cast them to their own types (was trying interfaces initially, but for debugging tried to cast to THEIR OWN TYPES), getting this error:
[A]DAL_QSYSCamper.NHibernateSessionBuilder cannot be cast to [B]
DAL_QSYSCamper.NHibernateSessionBuilder. Type A originates from 'DAL_QSYSCamper,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at
location 'C:\Users\myusername\AppData\Local\Temp\Temporary ASP.NET
Files\root\ad6e8bff\70fa2384\assembly\dl3\aaf7a5b0\84f01b09_b10acb01\DAL_QSYSCamper.DLL'.
Type B originates from 'DAL_QSYSCamper, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' in the context 'LoadNeither' at
location 'C:\Users\myusername\Documents\Projects\QSYS\Deleteme\UI\MVCClient\bin\DAL_QSYSCa
mper.DLL'.
This is happening while debugging in VS - VS manages to stop into the source DAL project even though I've loaded from assembly and the project is not refferenced by the website project (they're both in the solution).
I do understand the error, but I don't understand how and why the assembly is being used/loaded from two locations - I only load it once from the file and there's no referrence to the project.
Should mention that I also use Windsor for DI. The object that tries to extract the object from the session is A) from a class from that DAL assembly; B) is injected into a website class by Windsor. I will work on adding some sample code to this question, but wanted to put it out in case it's obvious what I do wrong.