我要序列化一个类类型的列表:
private static List<TradeData> Trades = new List<TradeData>();
[ZeroFormattable]
private class TradeData
{
[Index(0)]
public virtual string Symbol { get; set; }
[Index(1)]
public virtual DateTime utcDT { get; set; }
[Index(2)]
public virtual int SignedAmount { get; set; }
[Index(3)]
public virtual double MidPrice { get; set; }
public TradeData()
{
}
}
但是当我尝试执行此操作时出现以下错误:
var zf = ZeroFormatterSerializer.Serialize(Trades);
不支持Message = Type,发生无效错误:System.Lazy上的列表
1 InnerException:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Type is not supported, occurs invalid error: TradeData InnerException:System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Access is denied: 'Cobra.Simulz+TradeData'. at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type) at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock() at System.Reflection.Emit.TypeBuilder.CreateTypeInfo() at System.Lazy
1.CreateValue()1.LazyInitValue() --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
2 [] memberInfos)
at ZeroFormatter.Formatters.DynamicFormatter.BuildFormatter(ModuleBuilder builder, Type resolverType, Type elementType, Tuple
在ZeroFormatter.Formatters.DynamicFormatter.CreateTTypeResolver,T 在 ZeroFormatter.Formatters.Formatter.GetBuiltinFormatter [TTypeResolver,T](类型 t,TTypeResolver解析器)在 ZeroFormatter.Formatters.Formatter2..cctor() at ZeroFormatter.Formatters.ErrorFormatter
2.GetLength()在 ZeroFormatter.Formatters.CollectionFormatter3..ctor() --- End of inner exception stack trace --- at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at ZeroFormatter.Formatters.Formatter.GetBuiltinFormatter[TTypeResolver,T](Type t, TTypeResolver resolver) at ZeroFormatter.Formatters.Formatter
2..cctor()Source = ZeroFormatter