本文介绍了从VS ASP.NET开发服务器序列化主体的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在尝试捕获Web服务器上的安全主体CallContext,以便它自动流向通过另一台服务器上的远程访问访问的业务对象。 我正在测试替代品(Visual Studio 2005,.NET 2.0)。 我已经从IIS中的虚拟目录运行的ASP.NET客户端测试了我的代码,而不是在IIS中托管在IIS和远程机器上的业务对象。 span style =""> 现在,它ks在所有环境中但只有一个。 在"Web"的Visual Studio 2005项目选项中,当我选择"使用IIS Web服务器"选项时,代码运行正常。 当我选择"使用Visual Studio开发服务器"时(即,Cassini),我的ASP页面在Page_Load(我的测试代码所在的位置)之后的某处抛出以下异常: System.Runtime.Serialization.SerializationException未处理 Message ="类型未解析成员'NMDFrameworkTest.NMDContext,NMDFrameworkTest,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = aced533f1c49fb66'。" 来源= "WebDev.WebHost" StackTrace: 在Microsoft.VisualStudio.WebHost.Host.ProcessRequest(连接conn) tudio.WebHost.Server.OnSocketAccept(Object acceptedSocket) System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)中的face ="Times New Roman"> > 如果我在Page_Load中单步执行代码,我不会看到任何不妥之处事实上,我可以说业务逻辑正确地接收了我的身份。 我不确定之后我收到NMDContext序列化错误的地点或原因。 感谢任何帮助! 我正在使用一个可序列化的上下文包装器,几乎完全从最佳实践中复制doc at http://msdn2.microsoft.com/en-us/library/ms954586.aspx#damaz_enablingauthorizationinremotingapp 。 [可序列化] public class NMDContext : ILogicalThreadAffinative { 私人 IPrincipal m_Principal; public NMDContext( IPrincipal principal) { if (principal == null ) throw new ArgumentNullException (" principal" ,"参数不能为空。" ); m_Principal = principal; } public IPrincipal 校长 { get { 返回 m_Principal; } } } 在ASP.NET客户端,我正在做什么(目前),而不是从HttpContext当前用户中取出名称并将其作为GenericPrincipal打包在NMDContext中: m_Principal = new GenericPrincipal ( new GenericIdentity (Principal.Identity.Name), new string [] {} ); //置入调用上下文。 CallContext .SetData (RESERVED_CONTEXT_NAME, new NMDContext (m_Principal)); 在业务逻辑(服务器)方面,我按如下方式检索它: NMDContext context = CallContext .GetData(RESERVED_CONTEXT_NAME) as NMDContext ; 两者这些操作(在客户端和服务器上)通过与NMDContext本身存在于同一程序集中的帮助程序类来完成。 发展服务器在找到类型时遇到问题的可能性很大(这对我来说似乎不太可能,因为它显然加载了程序集),我在web.config中明确定义了代码库href到NMDContext。 但这似乎没有影响问题。 另一方面。 当我将NMDContext的程序集放入GAC时,问题就消失了。 我很沮丧。 解决方案 您是否能够自行解决此问题?我有完全一样的问题。我也看到我的业务逻辑层获取了我的对象,但出乎意料的是我得到了"未解析为成员的类型"异常。如果你可以通过让我知道你是如何解决这个问题来帮助我的,我将不胜感激。 提前致谢! I’m trying to capture the security principal on a web server in the CallContext so that it flows automatically to business objects that are accessed via remoting on another server. I’m currently testing alternatives (Visual Studio 2005, .NET 2.0). I’ve tested my code from an ASP.NET client running from a virtual directory in IIS against my business objects hosted in IIS both on localhost and on remote machines.  Right now, it works in all environments but one.   In the Visual Studio 2005 project options for "Web," when I select the option to "Use IIS Web server," the code runs fine.   When I select "Use Visual Studio Development Server" (i.e., Cassini), my ASP page throws the following exception somewhere after Page_Load (where my test code is): System.Runtime.Serialization.SerializationException was unhandled  Message="Type is not resolved for member 'NMDFrameworkTest.NMDContext,NMDFrameworkTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aced533f1c49fb66'."  Source="WebDev.WebHost"  StackTrace:       at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)       at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket)       at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state) If I step through my code in Page_Load, I don’t see anything irregular, and, in fact, I can tell that the business logic properly received my Identity.  I’m not certain where or why I’m receiving a NMDContext serialization error afterwards. Any help would be gratefully appreciated! I’m using a serializable context wrapper copied almost exactly from the best practice doc at http://msdn2.microsoft.com/en-us/library/ms954586.aspx#damaz_enablingauthorizationinremotingapp.     [Serializable]    public class NMDContext : ILogicalThreadAffinative    {        private IPrincipal m_Principal;         public NMDContext(IPrincipal principal)        {            if (principal == null)                throw new ArgumentNullException("principal", "The argument cannot be null.");             m_Principal = principal;        }         public IPrincipal Principal        {            get            {                return m_Principal;            }        }     } On the ASP.NET client side, I’m doing nothing more (at the moment) than plucking the name out of the HttpContext current user and packaging it in an NMDContext as a GenericPrincipal:             m_Principal = new GenericPrincipal(                new GenericIdentity(Principal.Identity.Name),                new string[] { }                );             // Put in call context.            CallContext.SetData(RESERVED_CONTEXT_NAME, new NMDContext(m_Principal)); On the business logic (server) side, I retrieve it as follows:             NMDContext context = CallContext.GetData(RESERVED_CONTEXT_NAME)                 as NMDContext; Both of these operations (on the client and the server) are being done via a helper class that exists in the same assembly as the NMDContext itself. On the off-chance that the developmental server was having problems finding the type (which seemed unlikely to me, since it clearly had loaded the assembly), I explicitly defined the codebase href to NMDContext in the web.config.  But that didn’t appear to affect the problem. On the other hand.  When I put NMDContext’s assembly in the GAC, the problem vanishes.  I’m flummoxed.   解决方案 Were you able to resolve this issue on your own?  I have the exact same problem.  I too see that my business logic layer gets my object, but then unexpectedly I get the 'Type not resolved for member' exception.  If you can help me out by letting me know how you resolved the issue I would greatly appreciate it. Thanks in advance! 这篇关于从VS ASP.NET开发服务器序列化主体的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 19:57