msIdentity的NullReferenceExceptio

msIdentity的NullReferenceExceptio

本文介绍了ClaimsIdentity的NullReferenceException安装.NET 4.5后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的.Net 4溶液在VS2010开发的,它使用用于定义当前请求的用户的IIdentity的实现。我现在想用vs2012继续它的发展。

I have an existing .Net 4 solution developed in vs2010, which uses an IIdentity implementation that is used to define the user of the current request. I now want to use vs2012 to continue it's development.

我已经打开在vs2012的解决方案,并设置属性目标框架内.NET 4然而,当我运行的解决方案,我得到当Web服务器反序列化GenericIdentity对象异常。中发生的异常

I have opened the solution in vs2012 and set the target framework in properties to be .Net 4. However when I run the solution, I get an exception when the web server is deserializing the GenericIdentity object. The exception occurs in

at System.Security.Claims.ClaimsIdentity.<get_Claims>d__0.MoveNext()
at System.Security.Principal.GenericIdentity.OnDeserializedMethod
                                                  (StreamingContext context)

异常的原因似乎是财产索赔未初始化。

The cause of the exception seems to be that the property Claims is not initialized.

我已经知道了:

  1. 的.Net 4.5更新.NET 4的目标机器上,而不是做一个侧并排安装。

  1. .Net 4.5 updates .Net 4 on the target machine rather than doing a side-by-side install.

GenericIdentity现在是来源于新类ClaimsIdentity在.net 4.5

GenericIdentity is now derived from the new class ClaimsIdentity in .Net 4.5

设置目标框架.NET 4中表示,虽然code仍与.NET 4.0运行时,执行4.5使用在幕后即你无法看到的层次结构在Visual Studio对象浏览器,但在调试器和反光镜显示推导。

Setting target framework to .Net 4 means that although the code is still running with .NET 4.0, the 4.5 implementation is used under the covers i.e. you can't see the hierarchy in the visual studio object browser but the debugger and reflector shows the derivation.

在GenericIdentity.OnDeserializedMethod访问ClaimsIdentity索赔财产不检查空,导致NullReferenceException异常

The GenericIdentity.OnDeserializedMethod accesses the ClaimsIdentity Claims property without checking for null, causing the NullReferenceException

一解决方案我碰到介入使我的自定义标识对象从System.MarshalByRefObject继承,但问题是,自定义标识对象由单点登录.dll文件,用于在所有提供系统在我们的组织。这意味着我必须把它得不到改变其继承heirachy。

One solution I came across involved making my custom Identity object inherit from System.MarshalByRefObject, but the problem is that custom Identity object is provided by a "Single Sign On" .dll that is used across all systems in our organisation. This means I have no access to it to change its inheritance heirachy.

有没有一种替代解决方案或workaraound这个问题?

Is there an alternative solution or workaraound for this problem?

推荐答案

这个问题是使用内置的Visual Studio的服务器时只发生,当我们作为一个团队使用IIS本地运行我们在开发用地,我们只是要住在一起,因为我刚刚花了太多时间在上面了。

This problem is only occurring when using the inbuilt Visual Studio server, and as we as a team use IIS locally to run our sites in development, we are just going to live with it as I've just spent too much time on it now.

这个问题看起来下一个AppDomain过渡到围绕对象序列化和反序列化,但我没有时间作进一步调查。

The problem looks to be around object serialization and deserialization following an appDomain transition, but I don't have time to investigate further.

更新:此问题不会与.NET 4.5.1发生

这篇关于ClaimsIdentity的NullReferenceException安装.NET 4.5后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 23:22