Serializable class:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Server { [Serializable] class Song { public int songID { get; set; } public string songName { get; set; } public string songArtist { get; set; } public string songAlbum { get; set; } public string songYear { get; set; } public byte[] songPicture { get; set; } public Song(int _songID, string _songName, string _songArtist, string _songAlbum, string _songYear) { songID = _songID; songName = _songName; songArtist = _songArtist; songAlbum = _songAlbum; songYear = _songYear; } } } 

I transfer from the server to the client

 Song thisSong = new Song(0, "HEYHEYHEYHEYHEYHEY", null, null, "nothing"); formatter.Serialize(stream, thisSong); 

I accept on the client

 do { song = formatter.Deserialize(stream) as Song; } while (stream.DataAvailable); 

When debugging, I found out that stream.DataAvailable = true

I can not understand what caused the problem, this exception pops up on the client

enter image description here

    1 answer 1

    You have different Song types on the server and on the client. Let me remind you that in the "most complete" type name is the name of the assembly, it is precisely this that is different. That is why during deserialization the client starts looking for a server assembly.

    Select the Song type and others like it in a separate library shared by the client and server.

    Better yet, switch to other serialization methods. The easiest option is to use [DataContract] and DataContractSerializer

    • How to allocate Song to a separate library? I do not fully understand what is required - zaki hatfild
    • @zakihatfild create a library and transfer there the type Song - Pavel Mayorov
    • I mean make dll from one class? - zaki hatfild
    • Everything worked, thanks - zaki hatfild