Protobuf-Net Silverlight: DataContract class has properties null or missing -


this 1 of class definitions within dll use in wcf service.

[datacontract] public class scenarioxml {     [datamember(order = 1)]     public long? tnrscenario { get; set; }     [datamember(order = 2)]     public long? tnrproject { get; set; }     [datamember(order = 3)]     public int? priority { get; set; }             // ...     [datamember(order = 19)]     public list<scenarioassetxml> scenarioassets { get; set; }     [datamember(order = 20)]     public list<calendarxml> calendars { get; set; }     [datamember(order = 21)]     public scenariotriggercollectionxml scenariotriggercollection { get; set; } } 

i'm using datacontract instead of protocontract, can expose class silverlight project through wsdl, , still use protobuf-net serialization.

now, when use following code in wcf service, original "scenario" , "restoredmodel" identical.

memorystream msteststring = new memorystream(); serializer.serialize<scenarioxml>(msteststring, scenario); string memento = convert.tobase64string(msteststring.toarray());  byte[] byteafter64 = convert.frombase64string(memento); memorystream afterstream = new memorystream(byteafter64); scenarioxml restoredmodel = serializer.deserialize<scenarioxml>(afterstream); 

however, when use same code in silverlight, tnrscenario value null. similarly, tnrscenarioasset property of objects in scenarioassets list null.

[datacontract] public class scenarioassetxml {     [datamember(order = 1)]     public long? tnrscenarioasset { get; set; }     [datamember(order = 2)]     public long? tnrscenario { get; set; }     [datamember(order = 3)]     public string asset { get; set; }     [datamember(order = 4)]     public string action { get; set; } } 

when make first property string, vanishes after (de)serialization. when put dummy bool first property, bool there, second property, in case scenarioassets, still null. there's weird going on here...

am doing somethign wrong, or bug?

edit: you're right marc! orders messed in wsdl-generated code.

[system.diagnostics.debuggerstepthroughattribute()] [system.codedom.compiler.generatedcodeattribute("system.runtime.serialization", "4.0.0.0")] [system.runtime.serialization.datacontractattribute(name="scenarioxml", namespace="http://schemas.datacontract.org/2004/07/datacollectiondll")] public partial class scenarioxml : object, system.componentmodel.inotifypropertychanged {      private system.nullable<long> tnrscenariofield;      private system.nullable<long> tnrprojectfield;      private system.nullable<int> priorityfield;      //...      [system.runtime.serialization.datamemberattribute()]     public system.nullable<long> tnrscenario {         {             return this.tnrscenariofield;         }         set {             if ((this.tnrscenariofield.equals(value) != true)) {                 this.tnrscenariofield = value;                 this.raisepropertychanged("tnrscenario");             }         }     }      [system.runtime.serialization.datamemberattribute(order=1)]     public system.nullable<long> tnrproject {         {             return this.tnrprojectfield;         }         set {             if ((this.tnrprojectfield.equals(value) != true)) {                 this.tnrprojectfield = value;                 this.raisepropertychanged("tnrproject");             }         }     }      [system.runtime.serialization.datamemberattribute(order=2)]     public system.nullable<int> priority {         {             return this.priorityfield;         }         set {             if ((this.priorityfield.equals(value) != true)) {                 this.priorityfield = value;                 this.raisepropertychanged("priority");             }         }     }     //... 

however, i'm not sure how correctly implement partial class? created in wcf service, seems confuse compiler. getting following errors:

  • error 6 'datacollectiondll.scenarioxml' not contain definition 'tnrscenario' , no extension method 'tnrscenario' accepting first argument of type 'datacollectiondll.scenarioxml' found (are missing using directive or assembly reference?)
  • error 2 cannot convert type 'datacollectiondll.scenarioxml [c:\projects\flowcontrol 1.7.1.1\flowcontrolfc.web\libraries\datacollectiondll.dll]' 'datacollectiondll.scenarioxml [c:\projects\flowcontrol 1.7.1.1\flowcontrolfc.web\dal\datacollectionclasses\scenarioxml.cs(31)]'

then tried in silverlight project, compiles fine doesn't solve problem. results same.

the partial class created:

namespace datacollectiondll {     [protocontract]     [protopartialmember(1, "tnrscenario")]     [protopartialmember(2, "tnrproject")]     [protopartialmember(3, "priority")]     //...     [protopartialmember(21, "scenariotriggercollection")]     partial class scenarioxml     {     } } 

it sounds used wsdl-generated proxies; can confuse things little bit, because protobuf-net really really cares numbers are, , wsdl can play fast , loose those. if see wsdl-generated proxy classes (in .designer.cs), i'm going assume problem. fortunately, code-generators use partial class, can add own partial class in separate file add information same type, in particular: more attributes. example:

namespace the.same.namespace {     [protocontract]     [protopartialmember(1, "tnrscenario")]     [protopartialmember(2, "tnrproject")]     // ...     [protopartialmember(21, "scenariotriggercollection")]     partial class scenarioxml { } } 

this merged compiler scenarioxml class, , should allow protobuf-net use correct numeric identifiers each property.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -