![](/img/trans.png)
[英]Object of type 'System.Int16' cannot be converted to type 'System.Nullable`1[System.Int32]
[英]Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose'
每当我尝试构建时,我都会收到此错误。 我刚刚安装了Visual Studio 2012和.Net 4.5,但这个项目仍然在2010年。
以下是我遇到问题的代码行:
private static MethodInfo _encode;
public static string Encode(CookieProtection cookieProtection, byte[] buf, int count)
{
return (string)_encode.Invoke(null, new object[] { cookieProtection, buf, count });
}
我收到一个ArgumentException was unhandled by user code
"Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose'"
ArgumentException was unhandled by user code
错误ArgumentException was unhandled by user code
, "Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose'"
我的开发环境和我的同事没有任何改变没有同样的问题,但他们也没有VS2012。
我发现一篇关于Sitecore 的文章有这个错误,但这是我见过的唯一一个弹出的地方。
他们在那里说,“这是因为在.NET 4.5中,System.Web中有一些新的命名空间”
他们的解决方案是:
这似乎是一个荒谬的解决方案,4.5和4不能在同一台机器上。
在我尝试卸载并重新安装一堆东西之前,是否有人知道可能导致此问题以及任何更好的解决方案?
评论还说要尝试: </setting name="login.rememberlastloggedinusername" value="false" >
但我也不想这样做。
正如@hvd所提到的,这段代码使用反射来调用Microsoft在.NET 4.5中更改的内部方法。
幸运的是,.NET 4.0引入了带有公共Encode()
和Decode()
方法的System.Web.Security.MachineKey
类,这些方法基本上与CookieProtectionHelper
的内部方法CookieProtectionHelper
。 请注意,使用CookieProtectionHelper.Encode()
加密的cookie将无法使用MachineKey.Decode()
进行解密。
另请注意,在.NET 4.5中,不推荐使用这些方法,而使用Protect()
和Unprotect()
。
在web.config中将值更改为false:
<setting name=”Login.RememberLastLoggedInUserName” value=”false” />
(来自: http : //truncatedcodr.wordpress.com/2012/06/20/fix-sitecore-and-net-framework-4-5/ )
如果您在使用CMS软件Ektron时看到此错误,则以下是其8.7发行说明 -
71233-如果您在web.config()中安装了8.6.1站点并启用了cookie加密,然后安装了Microsoft .NET Framework 4.5,则会看到以下错误:
Server Error in '/' Application.
Object of type 'System.Int32' cannot be converted to type System.Web.Security.Cryptography.Purpose'. This
是固定的。
正如其他答案中所提到的,一种解决方案是回滚到.Net framework 4.0。 Ektron在这种特殊情况下的其他答案是禁用cookie加密,或升级到8.7。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.