【问题标题】:Unable to find assembly, C#找不到程序集,C#
【发布时间】:2011-03-02 07:53:44
【问题描述】:

所以,这就是交易。我有两个 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: 找不到程序集“MyCBC,版本=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 记录) +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 阅读器)+788
   System.Web.SessionState.SessionStateItemCollection.ReadValueFromStreamWithAssert() +55
   System.Web.SessionState.SessionStateItemCollection.DeserializeItem(字符串名称,布尔检查)+281
   System.Web.SessionState.SessionStateItemCollection.get_Item(字符串名称)+19
   System.Web.SessionState.HttpSessionStateContainer.get_Item(字符串名称)+13
   System.Web.SessionState.HttpSessionState.get_Item(字符串名称)+13
   C:\Documents and Settings\sarsstu\My Documents\Projects\Testing\ASPTesting\ASPTesting\Default.aspx.cs:20 中的 ASPTesting._Default.Page_Load(Object sender, EventArgs e)
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o,对象 t,EventArgs e)+14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,EventArgs e)+35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔includeStagesAfterAsyncPoint)+627

提前感谢大家。

【问题讨论】:

  • FirstUserSession 是共享程序集的一部分还是只是基类?
  • FirstUserSession 不是基类,它是派生类之一。这里基本上有三个程序集在工作:共享 DLL,其中包含 BaseUserSession,然后是两个各自的应用程序程序集,其中包含 FirstUserSession 和 SecondUserSession(两者都继承自 BaseUserSession)。

标签: c# asp.net inheritance polymorphism


【解决方案1】:
【解决方案2】:

existing 不是 baseusersession,它是作为 baseusersession 的 firstusersession。因此,它可能会被转换回仅存在于 mycbc 程序集中的 firstusersession。

【讨论】:

    猜你喜欢
    • 2021-11-07
    • 1970-01-01
    • 2018-09-13
    • 2023-03-20
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多