I am getting this error now whenever I try to build. I just installed Visual Studio 2012 and .Net 4.5, but this project is still on 2010.
Here is the line of code I am having issues with:
private static MethodInfo _encode;
public static string Encode(CookieProtection cookieProtection, byte[] buf, int count)
{
return (string)_encode.Invoke(null, new object[] { cookieProtection, buf, count });
}
I receive an ArgumentException was unhandled by user code
error saying, "Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose'"
Nothing has changed in my dev environment and my co-workers are not having the same problem, but they also do not have VS2012.
I found an article about Sitecore having this error, but this is the only place I have seen it pop up.
There they say, "This is because in .NET 4.5 there are some new namespaces in System.Web "
Their solution is to:
This seem like a ridiculous solution that 4.5 and 4 cant be on the same machine.
Does anyone know what may be causing this and any better solutions before I try to un-install and re-install a bunch of stuff?
A comment also says to try: </setting name="login.rememberlastloggedinusername" value="false" >
but I don't want to do that either.
As @hvd alluded to, this code is using reflection to call internal methods which Microsoft changed in .NET 4.5.
Fortunately .NET 4.0 introduced the System.Web.Security.MachineKey
class with public Encode()
and Decode()
methods which accomplish basically the same thing as the internal methods in the CookieProtectionHelper
. Note that cookies that were encrypted with CookieProtectionHelper.Encode()
will not be able to be decrypted with MachineKey.Decode()
.
Also note that in .NET 4.5, these methods are deprecated in favor of Protect()
and Unprotect()
.
Change value to false in web.config:
<setting name=”Login.RememberLastLoggedInUserName” value=”false” />
(from: http://truncatedcodr.wordpress.com/2012/06/20/fix-sitecore-and-net-framework-4-5/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With