1

.NET에서 Portable Class Library로 iOS 및 Android 용으로 사용하려고 시도 중이며 DataContractJsonSerializer와 함께 Mono serialization issues을 가지고 있으므로이를 Protobuf.Protobuf.NET 프로세스 [OnSerializing] 있습니까? "비공개 회원은 전체 dll 컴파일과 함께 사용할 수 없습니다."

Protobuf에 대한 많은 질문과 MonoTouch에 대한 일부 오래된 문서가 있으므로 가능한/틀린 일을하고 있습니다. (제발 정정 해주십시오)

다음은 스왑 아웃하고 ProtoBuf.net으로 DataContractJsonSerializer를 대체하는 데 실패한 시도입니다.

오류는 OnSeralizing 실제로 공공 때문이다 외부 종속성이 없습니다,하지만 여전히

Protobuf 소스

나는 latest pull from Github을 사용하고 미리 컴파일되지 않습니다.

PCL 구성 :

DTO는 내 DTO에 Profile 344을 사용하고 Protobuf.NET_Portable

를 참조하고는

샘플 DTO이 "DTO"

무엇이 정확 코드는 protobuf와 함께 사용하려고합니다. 그것은 내가 포팅하는 미친 클래스의 대표입니다. (매우 복잡한). 객체가 매우 복잡하기 때문에 "DTO"를 따옴표로 넣었습니다 & 복잡하며 &을 단순화하는 데 매우 오랜 시간이 걸립니다.

using ProtoBuf; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Runtime.Serialization; 
using System.Text; 

namespace MonoBug 
{ 
    [ProtoContract] 
    [DataContract] 
    public abstract class GroupParameterizedSerializer2 
    { 

     [OnSerializing] 
     public void SerializeGroup(StreamingContext context) 
     { 


     } 

    } 
    [ProtoContract] 
    [DataContract] 
    public class SetMembershipProof2 : GroupParameterizedSerializer2 
    { 
     #region Serialization 

     /// <summary> 
     /// Serialization of a 
     /// </summary> 
     [ProtoMember(1)] 
     [DataMember(Name = "a", EmitDefaultValue = false, Order = 2)] 
     public string[] _a; 

     /// <summary> 
     /// Serialization of c 
     /// </summary> 
     [ProtoMember(2)] 
     [DataMember(Name = "c", EmitDefaultValue = false, Order = 3)] 
     public string[] _c; 

     /// <summary> 
     /// Serialization of r 
     /// </summary> 
     [ProtoMember(3)] 
     [DataMember(Name = "r", EmitDefaultValue = false, Order = 4)] 
     public string[] _r; 

     /// <summary> 
     /// Serialize a, c, r. 
     /// </summary> 
     /// <param name="context">The streaming context.</param> 
     [OnSerializing] 
     public void OnSerializing(StreamingContext context) 
     { 

      // This is a simluation ... 
      // existing code expects to perform calculations then proceed with serialization 
      List<string> t = new List<string>(); 
      t.Add("data1"); 
      _a = t.ToArray(); 

      t.Clear(); 
      t.Add("data2"); 
      _c = t.ToArray(); 

      t.Clear(); 
      t.Add("data3"); 
      _r = t.ToArray(); 
     } 

     #endregion 
    } 
} 

버그처럼 보이는 오류

Y:\DevUtil\Protobuf>precompile "\\psf\Home\Desktop\MonoBug\Types\bin\Debug\types 
.dll" -o:PortableTypes.dll -t:MonoBug 
protobuf-net pre-compiler 
Detected framework: .NETPortable\v4.0\Profile\Profile344 
Resolved C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPor 
table\v4.0\Profile\Profile344\mscorlib.dll 
Resolved C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPor 
table\v4.0\Profile\Profile344\System.dll 
Resolved \\psf\Home\Desktop\MonoBug\Types\bin\Debug\protobuf-net.dll 
Resolved C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPor 
table\v4.0\Profile\Profile344\System.Runtime.Serialization.dll 
Adding MonoBug.GroupParameterizedSerializer2... 
Adding MonoBug.SetMembershipProof2... 
Compiling MonoBug to PortableTypes.dll... 
Non-public member cannot be used with full dll compilation: MonoBug.SetMembershi 
pProof2.OnSerializing 

^^^^^^^^ 

    at ProtoBuf.Compiler.CompilerContext.CheckAccessibility(MemberInfo member) in 
\\psf\home\Documents\Git\protobuf-net\protobuf-net\Compiler\CompilerContext.cs: 
line 815 
    at ProtoBuf.Compiler.CompilerContext.EmitCall(MethodInfo method) in \\psf\hom 
e\Documents\Git\protobuf-net\protobuf-net\Compiler\CompilerContext.cs:line 558 
    at ProtoBuf.Serializers.TypeSerializer.EmitInvokeCallback(CompilerContext ctx 
, MethodInfo method, Boolean copyValue, Type constructType, Type type) in \\psf\ 
home\Documents\Git\protobuf-net\protobuf-net\Serializers\TypeSerializer.cs:line 
466 
    at ProtoBuf.Serializers.TypeSerializer.ProtoBuf.Serializers.IProtoTypeSeriali 
zer.EmitCallback(CompilerContext ctx, Local valueFrom, CallbackType callbackType 
) in \\psf\home\Documents\Git\protobuf-net\protobuf-net\Serializers\TypeSerializ 
er.cs:line 511 
    at ProtoBuf.Serializers.TypeSerializer.EmitCallbackIfNeeded(CompilerContext c 
tx, Local valueFrom, CallbackType callbackType) in \\psf\home\Documents\Git\prot 
obuf-net\protobuf-net\Serializers\TypeSerializer.cs:line 485 
    at ProtoBuf.Serializers.TypeSerializer.ProtoBuf.Serializers.IProtoSerializer. 
EmitWrite(CompilerContext ctx, Local valueFrom) in \\psf\home\Documents\Git\prot 
obuf-net\protobuf-net\Serializers\TypeSerializer.cs:line 343 
    at ProtoBuf.Meta.RuntimeTypeModel.WriteSerializers(CompilerOptions options, S 
tring assemblyName, TypeBuilder type, Int32& index, Boolean& hasInheritance, Ser 
ializerPair[]& methodPairs, ILVersion& ilVersion) in \\psf\home\Documents\Git\pr 
otobuf-net\protobuf-net\Meta\RuntimeTypeModel.cs:line 1516 
    at ProtoBuf.Meta.RuntimeTypeModel.Compile(CompilerOptions options) in \\psf\h 
ome\Documents\Git\protobuf-net\protobuf-net\Meta\RuntimeTypeModel.cs:line 1132 
    at ProtoBuf.Precompile.PreCompileContext.Execute() in \\psf\home\Documents\Gi 
t\protobuf-net\precompile\Program.cs:line 433 
    at ProtoBuf.Precompile.Program.Main(String[] args) in \\psf\home\Documents\Gi 
t\protobuf-net\precompile\Program.cs:line 32 
+0

이'OnSeralizing'이 경우 BinaryFormatter 및 SoapFormatter 같은 일부 시리얼에서 사용하는 사용하지만, 나는 (이 ProtoBuf 같은 모든 시리얼로 사용하는 공통 인터페이스입니다 생각하지 않습니다 모든 시리얼 라이저에는 자체 트릭이 있음) –

+0

아마도 "전체 DLL 컴파일"에 동적 또는 사전 계산이 필요하지 않다고 말하는 것일 수 있습니다. 아마도 정규 반사 방법이 필자의 경우에는 유일한 방법 일 것입니다. – LamonteCristo

+0

아마 당신은 시도하고 볼해야합니다. –

답변

2

. 이 방법은 분명히 public입니다. "이 방법이 효과가 없을 것"이라는 감지는 단순히이 경우에 실수를 범할 수 있습니다. 괜찮아 보인다. 나는 오늘 (나는 단지 나의 '전화 만 가지고있다) 나중에 나중에 보려고 노력할 것이다.

그리고 예 : protobuf - 그물 인식하고 [OnSerializing]