Question

My class causes BadImageFormatException (HRESULT: 0x8007000B) in MySerializer.Deserialize(Int32, Object, ProtoReader).

The class is not used anywhere. It's only manually added to the type model and compiled to the assembly.

Without this class everything is ok.

    using System;
    using ProtoBuf;

    namespace MyProject
    {
        [ProtoContract(ImplicitFields = ImplicitFields.PublicProperties, ExplicitPropertiesContract = true, IgnoreListHandling = true, AsReferenceDefault = true)]
        [Serializable]
        public class DataSharedStorage<T>
        {

            T _value;

            public DataSharedStorage()
            {
            }

            public T Value
            {
                get
                {
                     return _value;
                }

                set
                {
                     _value = value;
                }
            }

            public static implicit operator T(DataSharedStorage<T> storage)
            {
                return storage.Value;
            }
         }
    }

What could be the reason?

Was it helpful?

Solution

You should never add generic type definitions manually to the protobuf-net RuntimeTypeModel. This is my issue. Closed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top