Print Page | Close Window

CustomUser Deserializer Issue Has me Stumped:(

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2303
Printed Date: 17-Jun-2025 at 8:38am


Topic: CustomUser Deserializer Issue Has me Stumped:(
Posted By: benmcneill
Subject: CustomUser Deserializer Issue Has me Stumped:(
Date Posted: 14-Nov-2010 at 5:08pm
Hi Guys

I'm trying to implement ASP.net login in my IdeaBlade SL app. I have three assemblies (projects): EManager.Web, EManager.Views, and EManager.ViewModel.

In EManager.Web, I have a CustomUser class which is defined in the EManager.Web.Helpers namespace as follows:
[DataContract]
    public class CustomUser : UserBase, IKnownType
    {
        public CustomUser(IIdentity identity, IEnumerable<string> roles) :
            base(identity, roles) { }

        [DataMember]
        public Guid UserID { getset; }
    }
Also in EManager.Web, I have a CustomLoginManager clas in the same namespace as follows:

public class CustomLoginManager : AspAuthenticatingLoginManager
    {
        protected override IPrincipal CreateUserCore(string name, bool isAuthenticated, IEnumerable<string> roles)
        {
            var user = base.CreateUserCore(name, isAuthenticated, roles) as CustomUser;
            user.UserID = (Guid)Membership.GetUser(name).ProviderUserKey;
            return user;
        }
    }
Then, I have shared these two classes to my client, EManager.Views, and in my MainPage.cs client file, I have:
namespace EManager.Views
{
    using System;
    using System.Windows;
    using System.Windows.Media;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using IdeaBlade.EntityModel;
    using EManager.Web.Helpers;
    using EManager.Helpers;
    using EManager.Web.Models;
    public partial class MainPage : UserControl
    {
        private EManagerEntities EntityManager;
        EManager.Views.Controls.People pplwindow = new Controls.People();

        #region Load

            public MainPage() {
              InitializeComponent();
              Loaded += Page_Loaded;
            }

            void Page_Loaded(object sender, RoutedEventArgs e)
            {
                    CreateEntityManager();
                    Reset();
                    Login();
            }

            private void CreateEntityManager()
            {
                EntityManager = new EManagerEntities(false);
            }

        #endregion

        #region Login

            private void Login()
            {
                ILoginCredential credential = null;
                credential = new FormsAuthenticationLoginCredential("user""password""SERVER"true);

                EntityManager.ConnectAsync(op =>
                {
                    EntityManager.LoginAsync(credential, LoginCompleted, null);
                });
            }

            private void LoginCompleted(LoginOperation args)
            {
                if (args.HasError)
                {
                    string msg = args.Error.Message;
                    MessageBox.Show(msg);
                    return;
                }
                else
                {
                    CustomUser user = EntityManager.Principal as CustomUser;
                    string loginMsg = "Logged in " + user.Name;
                    GlobalVariables.GlbUserId = user.UserID;
                }
            }

            private void Logout()
            {
                EntityManager.Disconnect();
            }

        #endregion
    }
}
On running in browser however, it loads and I just keep getting:

"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://ideablade.com/EntityModel:LoginResult. The InnerException message was 'Element 'http://ideablade.com/EntityModel:Principal' contains data of the 'http://schemas.datacontract.org/2004/07/EManager.Web.Helpers:CustomUser' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'CustomUser' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."

I've used the 'IknownType' Attribute in CustomUser, so I'm not sure what's going on here, has me stumped. Would greatly appreciate your help! Thanks guys!

Cheers,
Ben



Replies:
Posted By: benmcneill
Date Posted: 14-Nov-2010 at 11:44pm
It's ok, fixed it, the XAP wasn't copying over:)



Print Page | Close Window