Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
C# Driver: "Ensure that known types are derived from the mapped class." error
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dan Terrill  
View profile  
 More options Oct 6 2012, 9:46 am
From: Dan Terrill <dan.terr...@c8sciences.com>
Date: Sat, 6 Oct 2012 06:46:26 -0700 (PDT)
Local: Sat, Oct 6 2012 9:46 am
Subject: C# Driver: "Ensure that known types are derived from the mapped class." error

Folks,

I just started working on a game as a hobby project, and when I execute
this query:

 if(gameCollection.Any(g => g.NumPlayers <
GameConstants.MAX_PLAYERS_PER_GAME))
            {
                return gameCollection.First(g => g.NumPlayers <
GameConstants.MAX_PLAYERS_PER_GAME);
            }

I get the error "
*Class MOMGame.GameObjects.Map cannot be assigned to Class
MOMGame.GameObjects.Game.  Ensure that known types are derived from the
mapped class.
Parameter name: type*"

Any idea what I'm doing wrong? The 2 classes are pretty simple, and listed
below.

Game:

[BsonKnownTypes(typeof(MOMGame.GameObjects.Map),
typeof(MOMGame.GameObjects.Location), typeof(MOMGame.GameObjects.Game),
typeof(MOMGame.GameObjects.UserInfo))]
    public class Game
    {
        [BsonId]
        public Guid Id { get; set; }
        public  Map Map { get; set; }

        public string Name { get; set; }

        public List<Guid> Players { get; set; }
        [BsonRepresentation(BsonType.Int32)]
        public int NumPlayers { get; set; }
        public Game()
        {
            Players = new List<Guid>();
            //if (!BsonClassMap.IsClassMapRegistered(typeof(Game)))
            //{
            //    BsonClassMap.RegisterClassMap<Game>(cm => cm.AutoMap());
            //}
        }

        public static void SaveGame(Game game)
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase("mom");
            var gameCollection = database.GetCollection<Game>("games");
            game.NumPlayers = game.Players.Count;
            gameCollection.Save(game);
        }

        public static Game GetNextGame()
        {
            var connectionString = "mongodb://localhost/?safe=true";
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase("mom");
            var gameCollection =
database.GetCollection<Game>("games").AsQueryable();
            if(gameCollection.Any(g => g.NumPlayers <
GameConstants.MAX_PLAYERS_PER_GAME))
            {
                return gameCollection.First(g => g.NumPlayers <
GameConstants.MAX_PLAYERS_PER_GAME);
            }
            else
            {
                return GameCreator.CreateGame();
            }
        }
    }

Map:

[BsonKnownTypes(typeof(MOMGame.GameObjects.Map),
typeof(MOMGame.GameObjects.Location) , typeof(MOMGame.GameObjects.Game),
 typeof(MOMGame.GameObjects.UserInfo))]
    public class Map
    {
        public Map()
        {
            //if (!BsonClassMap.IsClassMapRegistered(typeof(Map)))
            //{
            //    BsonClassMap.RegisterClassMap<Map>(cm => cm.AutoMap());
            //}
        }
        [BsonIgnore]
        public ILocation[][] Grid { get; set; }

        [BsonId]
        public Guid Id { get; set; }

        public string Name { get; set; }
        [BsonIgnore]
        public List<ILocation> Locations
        {
            get
            {

                List<ILocation> locs = new List<ILocation>();
                for (int i = 0; i < Grid.Length; i++)
                {
                    for (int j = 0; j < Grid[i].Length; j++)
                    {
                        locs.Add(Grid[i][j]);
                    }
                }
                return locs;

            }
        }
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Stam  
View profile  
 More options Oct 6 2012, 12:21 pm
From: Robert Stam <rob...@10gen.com>
Date: Sat, 6 Oct 2012 12:21:17 -0400
Local: Sat, Oct 6 2012 12:21 pm
Subject: Re: [mongodb-user] C# Driver: "Ensure that known types are derived from the mapped class." error

[BsonKnownTypes] is used to list known *subclasses* of a root class.

Try just removing the [BsonKnownTypes] and see how that works.

If there is still an issue after that, please provide a stack trace also.

Thanks.

On Sat, Oct 6, 2012 at 9:46 AM, Dan Terrill <dan.terr...@c8sciences.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »