Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Protobuf.NET是否处理[序列化]&引用;非公共成员不能与完整dll编译一起使用“;_C#_Xamarin.ios_Xamarin_Protobuf Net_Portable Class Library - Fatal编程技术网

C# Protobuf.NET是否处理[序列化]&引用;非公共成员不能与完整dll编译一起使用“;

C# Protobuf.NET是否处理[序列化]&引用;非公共成员不能与完整dll编译一起使用“;,c#,xamarin.ios,xamarin,protobuf-net,portable-class-library,C#,Xamarin.ios,Xamarin,Protobuf Net,Portable Class Library,我正在尝试从.NET到一个可移植的类库,以便与iOS和Android一起使用,并且正在使用DataContractJsonSerializer,所以我将用Protobuf替换它 我看到很多关于Protobuf的问题,还有一些关于MonoTouch的旧文档,所以我可能/可能做错了什么。(如有,请更正) 以下是我用ProtoBuf.net替换DataContractJsonSerializer的失败尝试 错误在于,onserialization实际上是公共的,没有外部依赖项,但仍然不会预编译 协议源

我正在尝试从.NET到一个可移植的类库,以便与iOS和Android一起使用,并且正在使用DataContractJsonSerializer,所以我将用Protobuf替换它

我看到很多关于Protobuf的问题,还有一些关于MonoTouch的旧文档,所以我可能/可能做错了什么。(如有,请更正)

以下是我用ProtoBuf.net替换DataContractJsonSerializer的失败尝试

错误在于,
onserialization
实际上是公共的,没有外部依赖项,但仍然不会预编译

协议源

我在用电话

PCL配置:

DTO正在引用

我正在使用我的DTO

样本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
    }
}

那看起来像个虫子。该方法显然是公开的,在这种情况下,“这不起作用”检测可能只是犯了一个错误。看起来不错。今天晚些时候我会去看看(我现在只有我的手机)


是的:protobuf net确实能够识别和使用
[onserialization]
onserialization
被一些序列化程序(如BinaryFormatter和SoapFormatter)使用,但我认为它不是所有序列化程序(如protobuf)都可以使用的通用接口(每个序列化程序都有自己的技巧),也许错误是“完整DLL编译”不需要动态或预计算。。在我的例子中,也许正则反射方法是唯一的方法。也许你应该试试看..我只是在运行时尝试了正则Protobuf,但得到了一个奇怪的错误,方法签名不正确。我还尝试了JSON.NET,这对这个示例很有效,所以我将继续处理这个不太理想的情况,直到得到更好的结果(protobuf)
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