我想序列化一个类类型的列表:
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 不受支持,发生无效错误:List
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() at System.Lazy 2[] memberInfos) at ZeroFormatter.Formatters.DynamicFormatter.CreateTTypeResolver,T at ZeroFormatter.Formatters.Formatter.GetBuiltinFormatter[TTypeResolver,T]( Type t, TTypeResolver resolver) 在 ZeroFormatter.Formatters.Formatter 2.GetLength() 在 ZeroFormatter.Formatters.CollectionFormatter 2..cctor() Source=ZeroFormatter1.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)
at ZeroFormatter.Formatters.DynamicFormatter.BuildFormatter(ModuleBuilder builder, Type resolverType, Type elementType, Tuple2..cctor() at ZeroFormatter.Formatters.ErrorFormatter
3..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