New Posts New Posts RSS Feed: CustomUser Deserializer Issue Has me Stumped:(
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

CustomUser Deserializer Issue Has me Stumped:(

 Post Reply Post Reply
Author
benmcneill View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Aug-2010
Posts: 11
Post Options Post Options   Quote benmcneill Quote  Post ReplyReply Direct Link To This Post Topic: CustomUser Deserializer Issue Has me Stumped:(
    Posted: 14-Nov-2010 at 11:44pm
It's ok, fixed it, the XAP wasn't copying over:)
Back to Top
benmcneill View Drop Down
Newbie
Newbie
Avatar

Joined: 26-Aug-2010
Posts: 11
Post Options Post Options   Quote benmcneill Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down