I've initialized the following variables as shown in one of the online tutorials:
Globals:
NetworkSessionProperties sessionProperties;
NetworkSession session;
protected override void Initialize()
{
// TODO: Add your initialization logic here
sessionProperties = new NetworkSessionProperties();
sessionProperties[(int)SessionProperty.GameMode] = (int)GameMode.Practice; // Game mode
sessionProperties[(int)SessionProperty.SkillLevel] = (int)SkillLevel.Beginner; // Score to win
sessionProperties[(int)SessionProperty.ScoreToWin] = 100;
// Create the session
session = NetworkSession.Create(NetworkSessionType.SystemLink, maximumLocalPlayers, maximumGamers, privateGamerSlots, sessionProperties);
session.AllowHostMigration = true;
session.AllowJoinInProgress = true;
base.Initialize();
}
I've also added this line in the game's constructor:
Components.Add(new GamerServicesComponent(this));
But why am I still getting this error when it tries to call NetworkSession.Create:
+ $exception {System.InvalidOperationException: The Gamer Services functionality must be initialized before you call this method. The easiest way to do that is to add a GamerServicesComponent to the Game.Components collection in the constructor of your Game class.
at Microsoft.Xna.Framework.GamerServices.GamerServicesDispatcher.get_PacketBuffer()
at Microsoft.Xna.Framework.Net.NetworkSession.BeginCreate(NetworkSessionType sessionType, Int32 maxLocalGamers, Int32 maxGamers, Int32 privateGamerSlots, NetworkSessionProperties sessionProperties, AsyncCallback callback, Object asyncState)
at Microsoft.Xna.Framework.Net.NetworkSession.Create(NetworkSessionType sessionType, Int32 maxLocalGamers, Int32 maxGamers, Int32 privateGamerSlots, NetworkSessionProperties sessionProperties)
at NetworkDemo.Game1.Initialize()
at Microsoft.Xna.Framework.Game.Run()
at NetworkDemo.Program.Main(String[] args)
} System.Exception {System.InvalidOperationException}