anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Serialize a System.RuntimeType throw a exception "Value cannot be null"? #342

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I have try serialize a property like this:
[ProtoMember(4)]
public Type[] paramTypes { get; set; }

It throw a exception "Value cannot be null" if paramTypes contains 
System.RuntimeType like 'T type' in GenericMethod.

Thanks!

Original issue reported on code.google.com by congdong...@gmail.com on 6 Dec 2012 at 11:16

GoogleCodeExporter commented 9 years ago
Do you have a complete repro I can look at?

Original comment by marc.gravell on 6 Dec 2012 at 6:20

GoogleCodeExporter commented 9 years ago
The attach file is my test project in Visual C# 2012. My idea also include in 
this project.

Thanks for looking my issue!

Original comment by congdong...@gmail.com on 7 Dec 2012 at 2:36

Attachments:

GoogleCodeExporter commented 9 years ago
That refers to the `T` in `TestClass<int>.GenericMethod<T>`, which is an open 
generic type (meaning: it has not been specified); quite simply, protobuf-net 
is not expecting to handle that, and I'm not sure it would be useful to add it.

If you really really need to support open generic types, feel free to hook the 
RuntimeTypeModel.Default.DynamicTypeFormatting event which will allow you to 
customise this logic in both directions (just fill in whichever property is 
`null`).

More likely, however, is that you need to support the *closed* generic method, 
i.e. `TestClass<int>.GenericMethod<string>`. That works *currently*: you simply 
haven't told it what `T` to use. For example:

    System.Reflection.MethodInfo method = typeof(TestClass<int>).GetMethod("GenericMethod").MakeGenericMethod(typeof(string));

Original comment by marc.gravell on 7 Dec 2012 at 7:41

GoogleCodeExporter commented 9 years ago
I know that 'T' is an open generic type, but I want to build a RMI library use 
in client server application (support method overloading), so I have to 
serialize the method with method name, parameter types and some others!

I think, this very useful!

Original comment by congdong...@gmail.com on 7 Dec 2012 at 12:06