Hay 3 proyectos:
Server - servidor de juegosClient - cliente del juegoShared - código compartido entre el Client y el Server El Server se comunica con Client mediante el envío de instancias de clase serializadas de MessagePack desde Shared . Al intentar deserializar una instancia de clase en el cliente
var packet = MessagePackSerializer.Deserialize<IPacket>(packetReader.GetRemainingBytesSegment());se lanza la siguiente excepción:
MessagePack.MessagePackSerializationException HResult=0x80131500 Message=Failed to deserialize World2D.Shared.Networking.Packets+IPacket value. Source=MessagePack StackTrace: at MessagePack.MessagePackSerializer.Deserialize[T](MessagePackReader& reader, MessagePackSerializerOptions options) at MessagePack.MessagePackSerializer.Deserialize[T](ReadOnlyMemory`1 buffer, MessagePackSerializerOptions options, CancellationToken cancellationToken) at World2D.Client.Networking.NetworkingSystem.<>c.<.ctor>b__2_0(NetPeer peer, NetPacketReader packetReader, DeliveryMethod deliveryMethod) in C:\Users\dclip\Desktop\world2d\client\world2d\src\Networking\NetworkingSystem.cs:line 25 at LiteNetLib.NetManager.ProcessEvent(NetEvent evt) at LiteNetLib.NetManager.PollEvents() at World2D.Client.Networking.NetworkingSystem.Update(GameTime gameTime) in C:\Users\dclip\Desktop\world2d\client\world2d\src\Networking\NetworkingSystem.cs:line 51 at MonoGame.Extended.Entities.World.Update(GameTime gameTime) in C:\Users\dclip\Desktop\world2d\shared\Shared\MonoGame.Extended\MonoGame.Extended.Entities\World.cs:line 89 at World2D.Client.Game1.Update(GameTime gameTime) in C:\Users\dclip\Desktop\world2d\client\world2d\Game1.cs:line 36 at Microsoft.Xna.Framework.Game.DoUpdate(GameTime gameTime) at Microsoft.Xna.Framework.Game.Tick() at Microsoft.Xna.Framework.SdlGamePlatform.RunLoop() at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior) at World2D.Client.Program.Main() in C:\Users\dclip\Desktop\world2d\client\world2d\Program.cs:line 11 Inner Exception 1: FileNotFoundException: Could not load file or assembly 'Server, Version=0.0.1.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. Aunque no estoy haciendo referencia al Server en el código de ninguna manera en el Client (ese es el propósito de Shared ), esta excepción ocurre una y otra vez. Si el servidor se agrega como una dependencia en el Administrador de referencias, todo funciona. ¿Pero por qué?
¿Cuál podría ser la razón? ¿Cuáles son las formas de depurarlo?
namespace World2D.Shared.Networking { public class Packets { [Union(0, typeof(Entities))] [Union(1, typeof(Entity))] public interface IPacket { [MessagePackObject] public class Entities : IPacket { [Key(0)] public List<MonoGame.Extended.Entities.Entity> entities; [SerializationConstructor] public Entities(List<MonoGame.Extended.Entities.Entity> entities) { this.entities = entities; } } [MessagePackObject] public class Entity : IPacket { [Key(0)] public MonoGame.Extended.Entities.Entity Value { get; set; } [SerializationConstructor] public Entity(MonoGame.Extended.Entities.Entity entity) { Value = entity; } } } } }