Q:

Serialization Exception caused by custom Identity and GenericPrincipal

I have been following an article on how to implement a custom Basic authentication with .net.
This is the article
The code uses an interface - IBasicUser - that derives from IIdentity.
The class BasicUser implements IBasicUser.
An instance of BasicUser is created and from that a GenericPrincipal is constructed.
IBasicUser bu = new BasicUser();
context.Context.User = new GenericPrincipal(bu, new string[] { });

When I run the code I get an exception.
Type 'Smithfamily.Blog.Samples.BasicUser' in assembly 'LM_TESTS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable. 

So I had a look at the System.Security.Principal.GenericIdentity class in Reflector and found that it is indeed marked with the attributes [Serializable. ComVisible(true)]
The Documentation on IIdentity doesn't say anything about implementations needing to be serializable. From the exception and Reflector I assume however that it does. So I add the [Serializable] attribute to the BasicUser class.
Now I get a new exception when I run the code.
[SerializationException: Type is not resolved for member 'Smithfamily.Blog.Samples.BasicUser,LM_TESTS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.]

I am not very familiar with Serialization and don't really understand what is going on or what the problem is. Please could you help enlighten me. Thanks.

A:

Are you hosting your web site in the VS Web Development Server?  If so, looks like you've stumbled onto a bug logged in MS Connect...
http://connect.microsoft.com/VisualStudio/feedback/details/274696/using-custom-identities-in-asp-net-fails-when-using-the-asp-net-developement-server
If I read this and the other posts about it correctly, the fix is GACing your DLL so that it can be found by .NET probing correctly and loaded at runtime.

