denghongcai / protobuf-net

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

VerificationException: Error verifying ProtoBuf.ProtoWriter in unity3d webplayer #327

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============
I've got an exception when using protobuf in the unity3d webplayer (just in it, 
in android,ios and standalone envinroment it works fine). The error is:

VerificationException: Error verifying ProtoBuf.ProtoWriter:WriteSingle 
(single,ProtoBuf.ProtoWriter): Invalid type (Float64) at stack for conversion 
operation. Numeric type expected at 0x0011 at MySerializer.Write 
(.SerializableQuat , ProtoBuf.ProtoWriter ) [0x00000] in :0

What steps will reproduce the problem?
1. Create and import a contract in unity3d plugins folder
2. Using Serialize() in a webplayer envinroment

What is the expected output? What do you see instead?
The expected output is the serialized stream

What version of the product are you using? On what operating system?
I'm using protobuf-net r580, the unity folder dlls. Unity is the 3.5.6f version

Please provide any additional information below.
I've found a little information here: 
http://answers.unity3d.com/questions/195005/does-protobuf-net-work-in-the-unity-
web-player.html but I don't know how to handle it.. In fact, before switching 
to the new protobuf error I got the "MethodAccessException: Attempt to access a 
private/protected method failed." error in the webplayer only, is it related?

willyrulez@gmail.com

Original issue reported on code.google.com by willyru...@gmail.com on 12 Oct 2012 at 10:46

GoogleCodeExporter commented 9 years ago
Hi; can you sell me what `SerializableQuat` looks like, so I can investigate? 
Also, does `SerializableQuat` work fine on the other platforms? or is your 
other-platform usage using different data types?

The `MethodAccessException` *sounds* a lot like the annoying "missing 
Interlocked" methods; there is a compiler symbol that switches that code to use 
a unity-compatible implementation. If so, using the unity build should help 
with that.

I'll happily try to investigate, but anything you can do to help me reproduce 
the scenario (hence: what does `SerializableQuoa` look like) would be really 
helpful.

Original comment by marc.gravell on 12 Oct 2012 at 11:22

GoogleCodeExporter commented 9 years ago
The class I'm serializing is declared as follows:

[ProtoContract]
public struct HitInformation
{
    [ProtoMember(1)]
    public bool isAttachedToPrevious;
    [ProtoMember(2)]
    public int i;
    [ProtoMember(3)]
    public int j;
    [ProtoMember(4)]
    public float timeStamp;
    [ProtoMember(5)]
    public int colorId;
    [ProtoMember(6)]
    public int brush;
    [ProtoMember(7)]
    public int scale;
    override public string ToString()
    {
        return ( isAttachedToPrevious + ":" + i + ":" + j + ":" + timeStamp + ":" + colorId + ":" + brush + ":" + scale );
    }
}

And this is the function that I'm using to serialize:
public string SerializeToString<T>(T obj)  where T : class {        
        using ( MemoryStream stream = new MemoryStream() ) {
            new hitStructSerializer().Serialize(stream,obj);
            return Convert.ToBase64String( stream.ToArray() );
        }
    }

I forgot to write that I'm using windows 7 64bit, if that matters and yes, in 
the other platforms I'm using the same class and data types, it's in fact the 
same application.

Here are the steps I've followed for creating my dlls:
I've created a new solution in monodevelop with my .cs HitStruct class and 
built it in a dll.
I've created another solution in monodevelop building a mono executable that 
does as follows:

using System;
using ProtoBuf;
using ProtoBuf.Meta;
using UnityEngine;

class MainClass {
    public static void Main (string[] args) {   
    var model = TypeModel.Create();     
    model.Add( typeof(HitInformation), true );  
    model.Compile( "hitStructSerializer", "hitStructSerializer.dll" );
    }
}

After that, I've called "mono myclass.dll" that created the other dll files.
At the end, I put all those files in the Plugins Unity editor.

Meanwhile, I could try to change the timestamp type from float to another type 
to see if the error comes again.

And thanks for the fast answer!

Original comment by willyru...@gmail.com on 12 Oct 2012 at 12:37

GoogleCodeExporter commented 9 years ago
The error message explicitly relates to "SerializableQuat". Is that a type in 
your system?

Original comment by marc.gravell on 12 Oct 2012 at 12:45

GoogleCodeExporter commented 9 years ago
No, it isn't.
My dll's method hitStructSerializer().Serialize is declared as 
    hitStructSerializer.Write ((HitInformation)obj, protoWriter);

and the Write() is
private static void Write (HitInformation hitInformation, ProtoWriter writer)

Original comment by willyru...@gmail.com on 12 Oct 2012 at 12:48

GoogleCodeExporter commented 9 years ago
I meant, the Serialize() is:
void TypeModel.Serialize (int num, object obj, ProtoWriter protoWriter)
{
    switch (num)
    {
    case 0:

        {
            hitStructSerializer.Write ((HitInformation)obj, protoWriter);
            return;
        }
    default:

        {
            return;
        }
    }
}

Original comment by willyru...@gmail.com on 12 Oct 2012 at 12:49

GoogleCodeExporter commented 9 years ago
k; that's **really** odd - the stacktrace shouldn't be making up random method 
signatures...

It sounds like something is very odd inside the generated hitStructSerializer. 
I don't know how much of this code is private, but is there any way you could 
email me a copy of the dlls (DTO dll and generated serialization dll), so that 
I can look at the generated IL? I'm not trying to steal your project - but 
understanding a verification exception without the IL is very hard, and I  
can't repro it just from the above. Is that an option at all? If it isn't, 
then: I guess it isn't - but worth asking.

Original comment by marc.gravell on 12 Oct 2012 at 12:57

GoogleCodeExporter commented 9 years ago
marc.gravell@gmail.com ?
Of course I can send you the dlls, there is no problem at all!

Original comment by willyru...@gmail.com on 12 Oct 2012 at 1:02

GoogleCodeExporter commented 9 years ago
Hmmm... it is indeed just the "unsafe" flag; it looks like the "unity" build is 
not including the right build symbol to omit this; I will re-deploy later today 
with this fixed.

Original comment by marc.gravell on 12 Oct 2012 at 1:34

GoogleCodeExporter commented 9 years ago
Thanks :D
And what about the mistery of the SerializableQuat ?

Original comment by willyru...@gmail.com on 12 Oct 2012 at 1:37

GoogleCodeExporter commented 9 years ago
No idea whatsoever on that; that is not a pb-net type. CLI going nuts, maybe.

Please try r594 from google-code. Let me know.

Original comment by marc.gravell on 12 Oct 2012 at 3:20

GoogleCodeExporter commented 9 years ago
It works! Awesome :D

Original comment by willyru...@gmail.com on 12 Oct 2012 at 3:37