Results 1 to 9 of 9

Thread: slice2cs: struct/class unmarshalling problem

  1. #1
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159

    slice2cs: struct/class unmarshalling problem

    I have a struct defined in Slice that is mapped to a class in C#, but I get a null-reference exception on unmarshalling. Here is the Slice:

    Code:
      ["clr:property"]
      struct Action {
        string Key;
        string Description;
      };
      
      ["clr:property"]
      struct ActionPermission {
        ::IServices2ICE::Action Action;
        bool IsAuthorized;
      };
      
      sequence<ActionPermission> ActionPermissionSeq;
    
      ["ami", "amd"] interface ClassifiedServices {
        . . .
        idempotent OpStatus GetClientPermissions(
            string clientGroupKey,
            string orderStatus,
            out ActionPermissionSeq permissions
          )
          throws ServiceError;
      };
    Now, debugging it, I can see that exception happens in the unmarshalling code for ActionPermission:

    Code:
            public void read__(IceInternal.BasicStream is__)
            {
                Action_prop.read__(is__);
                IsAuthorized_prop = is__.readBool();
            }
    When it is called, Action_prop is null, leading to the exception.

    Karl
    Karl Waclawek

  2. #2
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by kwaclaw View Post
    I have a struct defined in Slice that is mapped to a class in C#, but I get a null-reference exception on unmarshalling.
    It seems the marshalling code has the same problem:

    Code:
            public void write__(IceInternal.BasicStream os__)
            {
                Action_prop.write__(os__);
                os__.writeBool(IsAuthorized_prop);
            }
    It looks as if the code was generated assuming that Action was mapped to a struct instead of a class.

    Karl
    Karl Waclawek

  3. #3
    matthew's Avatar
    matthew is offline ZeroC Staff
    Name: Matthew Newhook
    Organization: ZeroC, Inc.
    Project: Internet Communications Engine
    Join Date
    Feb 2003
    Location
    NL, Canada
    Posts
    1,458
    Thanks Karl we'll look into this.

  4. #4
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Karl,

    I'm looking at your problem. Unfortunately, the fix isn't entirely trivial (and I was away on vacation all last week), which is why this is taking so long. I'll have a patch for you by tomorrow.

    Cheers,

    Michi.

  5. #5
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by michi View Post
    Karl,

    I'm looking at your problem. Unfortunately, the fix isn't entirely trivial (and I was away on vacation all last week), which is why this is taking so long. I'll have a patch for you by tomorrow.

    Cheers,

    Michi.
    Thanks, that is OK, we are still in development, and there is a simple workaround.

    And even you are entitled to some vacation.

    Karl
    Karl Waclawek

  6. #6
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Hi Karl, I've post a patch for this problem. Please let me know how you go with that.

    Cheers,

    Michi.

  7. #7
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by michi View Post
    Hi Karl, I've post a patch for this problem. Please let me know how you go with that.

    Cheers,

    Michi.
    There is now another issue with the generated code (in another part of my Slice) that does not allow it to compile. The problem is when a struct is mapped to a C# struct. The generated code does not initialize the struct when reading it from the stream. Here is the code generated - the function is the one called by IceInternal.DispatchStatus dispatch__(). I hope this is sufficient detail for you:

    Code:
            public static IceInternal.DispatchStatus GetPackagePubDates___(CommonServices obj__, IceInternal.Incoming inS__, Ice.Current current__)
            {
                checkMode__(Ice.OperationMode.Idempotent, current__.mode);
                IceInternal.BasicStream is__ = inS__.istr();
                string packageKey;
                packageKey = is__.readString();
                IServices2ICE.Date startDate;  // = new IServices2ICE.Date();
                startDate.read__(is__);
                string classKey;
                classKey = is__.readString();
                AMD_CommonServices_GetPackagePubDates cb__ = new _AMD_CommonServices_GetPackagePubDates(inS__);
                try
                {
                    obj__.GetPackagePubDates_async(cb__, packageKey, startDate, classKey, current__);
                }
                catch(_System.Exception ex)
                {
                    cb__.ice_exception(ex);
                }
                return IceInternal.DispatchStatus.DispatchAsync;
            }
    The type IServices2ICE.Date is a struct, and it should be initialized by calling the default struct constructor, see the comment in the code.

    Because of the compile issue I haven't tested your patch yet, although the generated code looks OK for it.

    Karl
    Karl Waclawek

  8. #8
    michi's Avatar
    michi is offline Registered User
    Name: Michi Henning
    Organization: Triodia Technologies
    Project: I have a passing interest in Ice :-)
    Join Date
    Feb 2003
    Location
    Brisbane, Australia
    Posts
    1,055
    Hi Karl,

    my apologies--I missed two spots in the code generator that were affected by the changes.

    I've updated the patch. Could you try again please?

    Thanks,

    Michi.

  9. #9
    kwaclaw is offline Registered User
    Name: Karl Waclawek
    Organization: Personal
    Project: Whiteboard application
    Join Date
    Sep 2004
    Location
    Oshawa, Canada
    Posts
    159
    Quote Originally Posted by michi View Post
    Hi Karl,

    my apologies--I missed two spots in the code generator that were affected by the changes.

    I've updated the patch. Could you try again please?

    Thanks,

    Michi.
    Good news - it works now.

    Thanks,


    Karl
    Karl Waclawek

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. C#: Nested struct unmarshalling problem
    By kwaclaw in forum Bug Reports
    Replies: 11
    Last Post: 09-27-2007, 12:01 PM
  2. A problem about struct of multi-items
    By klsmlzm in forum Help Center
    Replies: 4
    Last Post: 10-24-2006, 02:38 AM
  3. Problem with classes in struct
    By kovacm in forum Help Center
    Replies: 9
    Last Post: 10-06-2005, 01:49 AM
  4. why struct inherit class
    By code in forum Help Center
    Replies: 6
    Last Post: 10-06-2004, 01:17 PM
  5. May slice struct contain class?
    By minifat in forum Help Center
    Replies: 1
    Last Post: 08-09-2004, 09:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •