1 year ago

#284124

test-img

dclipca

Could not load file or assembly of project (when it is not referenced)

There are 3 projects:

  1. Server - game server
  2. Client - game client
  3. Shared - code shared between the Client and Server

Server communicates with Client by sending MessagePack-serialized class instances from Shared. When trying to deserialize one class instance on client

var packet = MessagePackSerializer.Deserialize<IPacket>(packetReader.GetRemainingBytesSegment());

the following exception is throwed:

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.

Though I am not referencing the Server in code in any way in Client (that's the purpose of Shared), this exception is happening over and over. If the Server is added as a dependency in the Reference Manager, everything works. But why?

What might be the reason? What are ways to debug it?

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;
                }
            }
        }
    }
}

c#

msgpack

0 Answers

Your Answer

Accepted video resources