denghongcai / protobuf-net

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

Using precompile with types that have interface members #381

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

I'm using silverlight 5 and I need it to be faster, so I'm trying to precompile 
my assembly with r632 version. 

The problem is that I have interfaces on the members of my types. It gives me 
an exception.
"Wrong type in the tail; expected System.Object, received namespace.IEntity"

Thanks!

Original issue reported on code.google.com by irving.r...@gmail.com on 24 May 2013 at 12:45

GoogleCodeExporter commented 9 years ago
Can you be more specific about where IEntity is used in this scenario, so that 
I can repro?

Original comment by marc.gravell on 24 May 2013 at 9:00

GoogleCodeExporter commented 9 years ago
I have two assemblies, one with the classes implementing the interfaces
and one with the interfaces, I had to use DynamicType to make it work,
because I can't know what types are going to implement my interface. So in
my first assembly I have a bunch of interfaces like this

[ProtoContract]
public interface IEmail
{
   [ProtoMember(1)]
   int Id{get; set;}
   [ProtoMember(2)]
   string Name{get; set;}
}
etc ...

In my second assembly I have the implementations
[ProtoContract]
public class ContactEntityCustom
{
     [ProtoMember(1,DynamicType=true)]
     public LIst<IEmail> Emails {get; set;}
}

[ProtoContract]
public class EmailCustom:IEmail
{
    [ProtoMember(1)]
    public int Id {get; set;}
    [ProtoMember(2)]
    public string Name {get; set;}
}

on IEmail in ContactentityCustom is where the error raises

Original comment by irving.r...@gmail.com on 24 May 2013 at 6:51

GoogleCodeExporter commented 9 years ago
I'm not sure this is your problem, but have you tried specifying the 
ProtoInclude?

[ProtoContract]
[ProtoInclude(3, typeof(EmailCustom))]
public interface IEmail
{
   [ProtoMember(1)]
   int Id{get; set;}
   [ProtoMember(2)]
   string Name{get; set;}
}

Original comment by xeri...@gmail.com on 4 Jun 2013 at 2:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
It cannot be used in that way. Because the interfaces are in a separate dll, 
they have no knowledge of the types that will implement them. I've attached an 
example

Original comment by irving.r...@gmail.com on 7 Jun 2013 at 6:44

Attachments: