Archived

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

Class union problem

Hello all,

I have the following code that describe union class :

Slice code
		enum VariantType
			{
				vtDOUBLE,
				vtLONG,
				vtSTRING,
				vtDATETIME,
				vtBOOL
			};

			class Variant
			{
				VariantType type;
			};

			class DoubleVariant extends Variant
			{
			   double value;
			};

			class LongVariant extends Variant
			{
			   long value;
			};

			class StringVariant extends Variant
			{
				string value;
			};

			class DateTimeVariant extends Variant
			{
				long value;
			};

			class BoolVariant extends Variant
			{
				bool value;
			};

an Ice server send throw IceStorm the message OnNewPricingResult() describe as follow :
                        class Quote
			{
				string key;
				Variant value;
			};

			sequence<Quote> QuoteSeq;

			class ParameterItem
			{
				string key;
				double value;
			};

			sequence<ParameterItem> ParameterItemSeq;

			class Parameter
			{
			   string name;
			   ParameterItemSeq data;
			};

			class PricingResult
			{
				string name;
				ParameterItemSeq parameter;
				QuoteSeq data;
			};

			sequence<PricingResult> PricingResultSeq;
			sequence<Parameter> ParameterSeq;

		interface PricingPublisher
		{
				   void OnNewPricingResult(string server, PricingResultSeq data);
		};

and my Ice client crash when receiving the message, on this piece of code :
                    [_System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011")]
                    public static Ice.DispatchStatus OnNewPricingResult___(PricingPublisher obj__, IceInternal.Incoming inS__, Ice.Current current__)
                    {
                        checkMode__(Ice.OperationMode.Normal, current__.mode);
                        IceInternal.BasicStream is__ = inS__.istr();
                        is__.startReadEncaps();
                        string server;
                        server = is__.readString();
                        Iron.Transport.IIce.PricingResult[] data;
                        {
                            int szx__ = is__.readAndCheckSeqSize(4);
                            data = new Iron.Transport.IIce.PricingResult[szx__];
                            for(int ix__ = 0; ix__ < szx__; ++ix__)
                            {
                                IceInternal.ArrayPatcher<Iron.Transport.IIce.PricingResult> spx = new IceInternal.ArrayPatcher<Iron.Transport.IIce.PricingResult>("::Iron::Transport::IIce::PricingResult", data, ix__);
                                is__.readObject(spx);
                            }
                        }
 CRASHED HERE                       is__.readPendingObjects();
                        is__.endReadEncaps();
                        obj__.OnNewPricingResult(server, data, current__);
                        return Ice.DispatchStatus.DispatchOK;
                    }

with the exception :
-! 06/04/12 19:27:31:798 IceTalker.exe: warning: dispatch exception:
   identity: 0eea78e0-c639-4aff-bac5-9fec33d106e1
   facet:
   operation: OnNewPricingResult
   remote host: 184.92.32.209 remote port: 2541
   Ice.SyscallException
       error = 0
      at IceInternal.IncomingBase.handleException__(Exception exc)
   Caused by: System.Reflection.TargetParameterCountException: Parameter count mismatch.
      at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, Cu
ltureInfo culture)
      at IceInternal.AssemblyUtil.createInstance(Type t)
      at IceInternal.BasicStream.DynamicObjectFactory.create(String type)


I suspect during Variant object unmarshalling...
my Ice version is 3.4.2 on visual C# 2010

Any ideas are welcome

Comments

  • xdm
    xdm La Coruña, Spain
    Hi Thierry,

    This is a problem in how Ice 3.4.2 retrieves the constructors of the generated classes, Ice expects that the default constructor is always the first defined constructor, but that order isn't warranted by .NET, other users has experienced failures with this when using .NET partial class feature to add custom constructors to generated classes.

    The best will be to apply the fix described in this post http://www.zeroc.com/forums/bug-reports/5477-partial-classes-user-generated-constructors.html, and rebuild Ice.

    Also if you don't use custom constructors is unlikely that you hit this bug, but is still better to use the other fix as the order of the constructors is not warranted by .NET.

    Let us know if you need more help with that.
  • Thanks very much for you help.

    You're right, I added constructors in partial generated classes.

    I will first remove the partial constructor to see if it's goes better, then I will add the proposed fix (I hope a official fix in 3.4.3)

    I made lots of tries and see that MSBuild is making a working binary where Visual 2010 failed, I first try to patch VS2010 with SP1
  • As expected VS2010 SP1 is not fixing the problem, so I removed my constructors in the partial generated classes and THAT fix the problem !!

    Thanks again xdm.