Disconnected API ( ChangeSet deserialization problem )

Thread is closed for posting
2 posts, 0 answers
  1. -=VIRT=-
    -=VIRT=- avatar
    4 posts
    Member since:
    Jun 2005

    Posted 12 Jan 2010 Link to this post

    Hello!

    I the beginner in "Open Access ORM", but have very much interested me one of possibilities of this ORM systems "Disconnected API". At present I study possibilities ORM and I try to make an elementary example, but unfortunately it does not work for me.

    The problem description:

    It is necessary to make the distributed application, consisting of 3 projects:

    1) WinForms Application (the client application, is used .NET Framework 2.0)
    2) Model Class Library (Library containing mine business objects "Persistent", is used .NET Framework 2.0)
    3) XML Web Service (Web service, my middle level, it not WCF, but is allowed use .NET Framework 3.5)

    Windows the client uses mine ObjectContainer, and access to the data carries out one of methods XML Web Service

    My XML Web Service contain this code:

     

        Private Function GetSerializedChangeSet(ByVal listName As StringByVal scope As IObjectScope, ByVal queryable As ObjectAs Byte()  
            Dim container As New ObjectContainer()  
            ' define the fetch groups used in the copy, by default all columns  
            Dim collector As IObjectCollector = New FetchGroupCollector(FetchGroupCollector.DefaultFetchGroup)  
            container.CopyFrom(scope, queryable.[GetType]().Name, queryable, collector)  
            ' get everything in the container as a changeset  
            Dim changeSet As ObjectContainer.ChangeSet = container.GetContent()  
            Dim outstream1 As New MemoryStream()  
            Dim format1 As New System.Runtime.Serialization.Formatters.Soap.SoapFormatter()  
            format1.Serialize(outstream1, changeSet)  
            ' deserialization test ... passed ...  
            Dim cnt As New ObjectContainer()  
            Dim ms As New MemoryStream(outstream1.ToArray())  
            cnt.Apply(format1.Deserialize(ms))  
            ' return serialized data  
            Return outstream1.ToArray()  
        End Function 
     
        <WebMethod()> _  
        Public Function GetContactGroups() As Byte()  
            Dim changeSet As ObjectContainer.ChangeSet = Nothing 
            Using scope As IObjectScope = ServiceScopeProvider.GetNewObjectScope()  
                Dim queryable = From q In scope.Extent(Of ContactGroup)() Select q  
                ' return serialized data to client ...  
                Return GetSerializedChangeSet("ContactGroups", scope, queryable)  
            End Using  
        End Function 

    Web method GetContactGroups(), work normally and return to client serialized ChangeSet, contained 2 object from DB.
    Here is my WinForm client code:

    Try 
       Private _client As New Service1.Service1()  
       Dim buf() As Byte = _client.GetContactGroups()  
     
       Dim Container As New ObjectContainer()  
       Dim ms As New MemoryStream(buf)  
     
       Dim format1 As New System.Runtime.Serialization.Formatters.Soap.SoapFormatter()  
       Dim chs As ObjectContainer.ChangeSet = format1.Deserialize(ms)  
     
       ' In this line throws exception !!! <<<  
       Container.Apply(chs)'<<<  
    Catch ex As Exception  
       'Exception throws  
     
    End Try 

    Line "Container.Apply(chs)" throws exception:
    "System.Reflection.TargetInvocationException"

    System.Reflection.TargetInvocationException was caught  
      Message="Адресат вызова создал исключение." 
      Source="mscorlib" 
      StackTrace:  
           в System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)  
           в System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)  
           в System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)  
           в System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)  
           в System.Runtime.Serialization.ObjectManager.DoFixups()  
           в System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)  
           в System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)  
           в Telerik.OpenAccess.ObjectContainer.Unwrap(ChangeSet cs)  
           в Telerik.OpenAccess.ObjectContainer.Apply(ChangeSet changes, Boolean force)  
           в Telerik.OpenAccess.ObjectContainer.Apply(ChangeSet changes)  
           в WinFormClient.Form1.Form1_Load(Object sender, EventArgs e) в C:\Users\Дмитрий\Documents\Visual Studio 2008\Projects\Telerik\ORM\Learn\1_ORM_Enable\WinFormClient\Form1.vb:строка 44  
      InnerException: System.TypeLoadException  
           Message="Type 'Model.ContactGroup' could not be found." 
           Source="Telerik.OpenAccess" 
           TypeName="" 
           StackTrace:  
                в Telerik.OpenAccess.RT.TypeResolver.AssociateTypeName(String dotnetname, Boolean complain)  
                в Telerik.OpenAccess.RT.TypeResolver.ResolveTypeName(String dotnetname, Boolean complain)  
                в Telerik.OpenAccess.RT.DisconnectedStateManager..ctor(SerializationInfo info, StreamingContext context)  
           InnerException:   
     

    As you can see very strange things are observed in section "InnerException", there is said that (Type ' Model.ContactGroup ' could not be found)...

    Thus mine WinFormClient the project has the correct reference to library of classes "Model". If to come in Class View that it is possible to see the reference to library Model and directly class ' Model.ContactGroup '.

    I absolutely understand nothing...
    What I do wrong???

  2. -=VIRT=-
    -=VIRT=- avatar
    4 posts
    Member since:
    Jun 2005

    Posted 12 Jan 2010 Link to this post

    Problem solved!!!
     
    I read this:
    http://www.telerik.com/community/forums/orm/databases/system-reflection-targetinvocationexception-in-disconnected-api.aspx

    Most likely the library of classes was not in time yet will be loaded in Default Application Domain. It sounds strange, but I have added an empty class in my library "Model" and named it "ActivationClass", and have created a copy of this class at start of mine WinFormClient appendices - all has earned!!!

    Here an solution example:

    Try    
       ' THIS IS SOLUTION <<<<<<<<<  
       Dim ac As New Model.ActivationClass() '<<<  
     
       Private _client As New Service1.Service1()     
       Dim buf() As Byte = _client.GetContactGroups()     
        
       Dim Container As New ObjectContainer()     
       Dim ms As New MemoryStream(buf)     
        
       Dim format1 As New System.Runtime.Serialization.Formatters.Soap.SoapFormatter()     
       Dim chs As ObjectContainer.ChangeSet = format1.Deserialize(ms)     
        
       ' Now this line, works fine :)   
       Container.Apply(chs)'<<<     
    Catch ex As Exception     
       'No exceptions ...    
        
    End Try    
     
Back to Top