Archived

This forum has been archived. Please start a new discussion on GitHub.

Problem with classes in struct

Is it possible to have class inside struct?

I have slice files like this:
class PropertyValue {
};

interface BoolTInterface {
	nonmutating bool getBoolValue();
};

class BoolT extends PropertyValue implements BoolTInterface {
	bool boolValue;
};	

struct PropertySetting {
	PropertyValue value;
};
sequence<PropertySetting> PropertySettingSeq;

struct ModuleAskingForCreation {
	PropertySettingSeq propertySetting;
};

sequence<ModuleAskingForCreation> ModuleAskingForCreationSeq;

interface test {
	nonmutating ModuleAskingForCreationSeq getModulesAskingForCreation();	
	nonmutating PropertyValue getProperty(string propertyName);
};

I have factory for instances of PropertyValue both on clien and on server. I have no problems with function getProperty, but when calling getModulesAskingForCreation it has to return some ModuleAskingForCreation with PropertySetting with value set to some instance of PropertyValue, but client receives null even if server returns for example instance of BoolT.

We are using Ice for C#

thank you,
Michal

Comments

  • matthew
    matthew NL, Canada
    Yes, this works. If you cannot work out the issue then post a self-contained compilable complete example and we'll take a look.

    Are you sure you have all the object factories installed with the correct type-id?

    Matthew
  • There is small examle representing this bug

    I am adding attachment with compilable complete example.
  • Again, thanks for your bug report! This is yet another problem in the generated code. I'm working on a fix for this. (Note that this isn't the same problem as the one you reported in http://www.zeroc.com/vbulletin/showthread.php?t=1612).

    Thanks,

    Michi.
  • Unfortunately, a fix for this problem is non-trivial.

    As a work-around in the mean time, can you apply the patch I posted for the "cs:class" metadata problem, and use the class mapping for the struct? This should get you off the hook.

    Cheers,

    Michi.
  • thank you, I will try the fix "cs:class bug", but fix for this bug is for me much more important

    Michal
  • matthew
    matthew NL, Canada
    Fixing this bug is very non-trivial. We're having extensive discussions internally on the best approach...

    The simplest way for you to work around this bug is to map your structs to classes using the ["cs:class"] metadata attribute, as Michi suggested. If you do this then the class within the slice struct should work.

    Will this not work for you for some reason?
  • oh, I understand now, thanks, I will try it
  • I have tried it and it works, thak you
  • I finally got back to this and worked out how to fix it. The problem only shows up if:

    - You have a sequence of structures.

    - You use the structure mapping (instead of the class mapping) for these structures.

    - The structures contain one or more class members.

    Otherwise, for structures that are not sequence elements, marshaling works correctly even if the structures contain class members.

    The fix is fairly complex, so I can't offer you a patch, but the fix will be included in Ice 3.0.

    Cheers,

    Michi.