繁体   English   中英

找不到程序集,C#

[英]Unable to find assembly, C#

所以,这是交易。 我有两个ASP.NET应用程序,它们都使用SQLServer会话状态管理。 它们也都使用同一台服务器。 我在外部DLL中有一个自定义会话类,该类完全实现了序列化,并且两个应用程序都已引用该类。 每个应用程序都有一个从DLL类继承的类,并且两个应用程序都将各自的类用于其会话状态。

现在,我想要完成的是,如果您想转到另一个应用程序,它可以在会话中查找(它们都使用相同的会话密钥),并将那里的现有对象作为基础(DLL中的一个) ),提取您需要的所有登录信息,然后用您自己的会话对象覆盖。 不幸的是,当第二个应用程序尝试读取会话时,似乎在寻找第一个应用程序的DLL,而当找不到它时,它将引发异常。

我的逻辑有缺陷吗?

这是一个例子:

// Global.asax of the 1st app  
protected void Session_Start(object sender, EventArgs e)  
{  
    Session.Add(  
        "UserSessionKey",  
        new FirstUserSession()); // FirstUserSession inherits from BaseUserSession  
}

现在是第二个应用程序:

// Global.asax of 2nd app
protected void Session_Start(object sender, EventArgs e)
{
    if (Session["UserSessionKey"] != null)
    {
        BaseUserSession existing = (BaseUserSession)Session["UserSessionKey"];

        SecondUserSession session = new SecondUserSession(); // This also inherits from BaseUserSession

        session.Authenticated = existing.Authenticated;
        session.Id = existing.Id;
        session.Role = existing.Role;

        Session.Add("UserSessionKey", session);
    }
    else
    {
        Session.Add("UserSessionKey", new SecondUserSession());
    }
}

这是异常堆栈跟踪。 在这种情况下,“ MyCBC”是第一个应用程序的真实名称,“ ASPTesting”是第二个应用程序。

[SerializationException: Unable to find assembly 'MyCBC, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]
   System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() +1871092
   System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) +7545734
   System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) +120
   System.Runtime.Serialization.Formatters.Binary.ObjectMap.Create(String name, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) +52
   System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) +190
   System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) +61
   System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() +253
   System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +168
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +203
   System.Web.Util.AltSerialization.ReadValueFromStream(BinaryReader reader) +788
   System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert() +55
   System.Web.SessionState.SessionStateItemCollection.DeserializeItem(String name, Boolean check) +281
   System.Web.SessionState.SessionStateItemCollection.get_Item(String name) +19
   System.Web.SessionState.HttpSessionStateContainer.get_Item(String name) +13
   System.Web.SessionState.HttpSessionState.get_Item(String name) +13
   ASPTesting._Default.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\sarsstu\My Documents\Projects\Testing\ASPTesting\ASPTesting\Default.aspx.cs:20
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

预先感谢大家。

存在不是基本用户会话,而是将第一个用户会话转换为基本用户会话。 这样,它有可能被转换回仅存在于mycbc程序集中的firstusersession。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM