PrepareSerializer call without generic classes

I am using reflection to find all classes in my project that inherit from Packet.Base

Each of these classes has ProtoBuf attributes.

I just experienced Exception - Timeout while validating the metadata of my project and want to implement PrepareSerializer without having to go through and add all the different class types in there.

Is there an easy way that I can dynamically prepare classes given that I have a type from reflection without the need to call

ProtoBuf.Serializer.PrepareSerializer(Of Instruction)()
ProtoBuf.Serializer.PrepareSerializer(Of NoOperation)()


or adding

Public MustOverride Sub Prepare()


base class and then in each class

Public Overrides Sub Prepare()
    Serializer.PrepareSerializer(Of TimeSynchronise)()
End Sub


This is the loading mechanism I'm using, a pretty simple reflection load.

Public Class CompatiblePackets
    Inherits Dictionary(Of Packet.PacketType, Base)

    Public Sub New()
        Dim theAssembly As Assembly = Assembly.GetExecutingAssembly
        For Each t As Type In theAssembly.GetTypes
            If t.BaseType Is GetType(Base) Then
                Dim p As Base = CType(t.Assembly.CreateInstance(t.FullName), Base)
                Me.Add(p.PacketTypeIndicator, p)
                End Try
            End If
    End Sub

    public sub Prepare
    end sub 



source to share

1 answer

Yes, you can call it without generics:




  • RuntimeTypeModel.Default

    - default type model used by methods Serializer.*

    (v2 supports parallel independent type models)
  • indexer [type]

    does and implicit Add

    , if not present, using default behavior (attributes) - and therefore most metadata parsing
  • CompileInPlace()

    the IL is optimized for the type

You can also zoom in a little RuntimeTypeModel.Default.MetadataTimeoutMilliseconds




All Articles