Message=ObjectManager 地址信息无效 程序中有问题

2024-08-22 10:47:04 浏览数 (1)

System.Runtime.Serialization.SerializationException

HResult=0x8013150C

Message=ObjectManager 发现链接地址信息的数目无效。这通常表示格式化程序中有问题。

Source=mscorlib

StackTrace:

在 System.Runtime.Serialization.ObjectManager.DoFixups()

在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)

/// <summary>

/// V1测试过程用到的类

/// </summary>

[Serializable]

public class ObjectItem

{

public string TestStr { get; set; }

}

/// <summary>

/// V1测试过程用到的结构体

/// </summary>

[Serializable]

public struct StructItem

{

在 System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler

handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

在 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.

Deserialize(Stream serializationStream, www.laipuhuo.com HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)

public string TestStr;

}

/// <summary>

/// 自定义序列化对象

/// </summary>

[Serializable]

public class MyObject

{

public bool BoolMember { get; set; }

public int IntMember { get; set; }

}

/// <summary>

/// 程序入口

/// </summary>

class Program

{

static void Main(string[] args)

{

var obj = new www.laipuhuo.com MyObject();

obj.BoolMember = true;

obj.IntMember = 10000;

IFormatter formatter = new BinaryFormatter();

Stream stream = new FileStream("data.dat", FileMode.Create, FileAccess.Write, FileShare.None);

formatter.Serialize(stream, obj);

stream.Close();

}

}

public class Person {

public string Id www.laipuhuo.com { get; set; }

public string Name { get; set; }

public int Age { get; set; }

public void Say(string word) {

Console.WriteLine($"{Name} Say: {word}");

}

}

public class PersonAgeChangeEvent {

public string Id { www.laipuhuo.com get; private set; }

public int Age{ get; private set; }

public PersonAgeChangeEvent(string id, int age){

this.Id = id;

this.Age = age;

}

}

public class PersonUpdateCommandHandler {

private PersonUpdateCommand Command;

public PersonUpdate www.laipuhuo.com CommandHandler(PersonUpdateCommand command) {

this.Command = command;

}

public void Handle() {

var person = GetPersonById(Command.Id);

if(person.Age != Command.Age) {

//生成并发送事件

var @event = www.laipuhuo.com new PersonAgeChangeEvent(Command.Id, Command.Age);

EventBus.Send(@event);

}

}

}public class CommandBus : ICommandBus

{

private readonly ICommandHandlerFactory handlerFactory;

public CommandBus(www.laipuhuo.com ICommandHandlerFactory handlerFactory)

{

this.handlerFactory = handlerFactory;

}

public void Send<T>(T command) where T : ICommand

{

var handler = handlerFactory.GetHandler<T>();

if (handler www.laipuhuo.com == null)

{

throw new Exception("未找到对应的处理程序");

}

handler.Execute(command);

}

}

0 人点赞