Open dtchepak opened 13 years ago
can that be reproduced using just DP?
Confirmed this is not a DP problem. Following code runs fine using DynamicProxy directly:
public class Class1 {
[Test]
public void TestName() {
var gen = new ProxyGenerator();
var root = gen.CreateClassProxy<Root>(new DoNothingInterceptor());
var formatter = new BinaryFormatter();
Root newRoot = null;
using (var stream = new MemoryStream()) {
formatter.Serialize(stream, root);
stream.Position = 0;
newRoot = formatter.Deserialize(stream) as Root;
}
}
}
[Serializable]
public class DoNothingInterceptor : IInterceptor { public void Intercept(IInvocation invocation) { } }
[Serializable]
public abstract class Root { public abstract string Data { get; set; } }
Reported on the mailing list.
When I run this, I get the following error (happens at the Serialize() call):
System.MethodAccessException was unhandled Message=Attempt by method 'Castle.Proxies.RootProxy.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' to access method 'Castle.DynamicProxy.Generators.Emitters.TypeUtil.Sort(System.Reflection.MemberInfo[])' failed. Source=DynamicProxyGenAssembly2 StackTrace: at Castle.Proxies.RootProxy.GetObjectData(SerializationInfo , StreamingContext ) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) at SerializeNSubstitute.Program.Main(String[] args) in G: \JasonBock\Personal.NET Projects\SerializeNSubstitute\Program.cs:line 18 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
I looked at the embedded Castle.DynamicProxy stuff in the NSubstitute DLL and the Sort() method exists, but this is occuring in the proxy itself, so I'm not sure what's going on there.