![](/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.