I am getting a strange error when I am upating a project on a website.
[A]StDataAccess.AgentInfo cannot be cast to [B]StDataAccess.AgentInfo.
Type A originates from 'App_Code.mwvc4o1b, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\online_7\b2fb7384\92a5cc98\App_Code.mwvc4o1b.dll'.
Type B originates from 'App_Code.05yjxsnv, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'Default' at location 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\online_7\b2fb7384\92a5cc98\App_Code.05yjxsnv.dll'.
As you can see, the Namespace/Class is the same, I did not change anything to that class between compilations, but I changed to another class in the parent namespace (StDataAccess). AgentsInfo is a pretty simple class, with 10 properties (string/int). Nothing complex. The error happens while I am retriecing this class from a session:
AgentInfo ag = (AgentInfo) HttpContext.Current.Session["AgentInfo"];
Any ideas?
Basically you've updated the assembly - the objects in your session are from the "old" assembly, and you can't cast to a type in the "new" assembly, as types are tightly bound to their originating assembly.
Options:
See more on this question at Stackoverflow