Options

"Call to member ErrorCode failed" error in RTC Automation

veerleverbrveerleverbr Member Posts: 7
edited 2012-02-13 in NAV Three Tier
I have an automation class Functional Error which is defined as
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [ProgId("FunctionalError")]
    [ComVisible(true)]
    [Guid("0476fd84-061f-4b17-a1c0-c39c1ed2d5d1")]
    public class FunctionalError
    {
        /// <summary>Code of the error</summary>
        public int ErrorCode { get; internal set; }

        /// <summary>Description of the error code</summary>
        public string ErrorType { get; internal set; }

        /// <summary>The message describing what went wrong on the server side</summary>
        public string ErrorReason { get; internal set; }

        /// <summary>The location where the error occured on the server side</summary>
        public string ErrorLocation { get; internal set; }

        /// <summary>The OriginalAttributeValue for the error.</summary>
        public string OriginalAttributeValue { get; internal set; }
    }

I have another automation class which, in case of an error, returns an instance of this class. When trying to get the ErrorCode from it in RTC, I get the error:

The message is for C/AL programmers: The call to member ErrorCode failed. Method "Microsoft.Dynamics.Nav.Runtime.NavAutomation.ErrorCode" not found.

I found some similar error messages, but they are all about automation variables of special types like enum, datetime, currency. But this is a simple integer. I don't understand why RTC cannot find it.

Any idea's?

Comments

  • Options
    beranberan Member, Microsoft Employee Posts: 80
    Are you sure that you are having the right class at hand? If you compile it your self - it could be a little out of date. So verify dates.

    Could you try making all properties public instead of the setters internal? They are called with reflection and with a series of binding flags.
    Eric Beran
    Software Design Engineer II
    Dynamics NAV Office 365
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Options
    veerleverbrveerleverbr Member Posts: 7
    Well, I tried making the setters public, but it makes no difference.
    Since the getters are public, it shouldn't make a difference.

    I also tried renaming the property to "FuncErrorCode", in case "ErrorCode" is some sort of reserved word, but that doesn't help either.
    I also tried making it a string instead of integer, but it doesn't help.

    I have lots of other classes in my automation dll which are used in the code before the error occurs. And they all work fine.
    Only difference I see is that this class instance is returned by a property of another class, which comes from a collection that is a property on another class and this last one is returned by a method, see explanation below. So what I mean is that the class is not instantiated in NAV with the create statement, it is created in the .NET code and returned in a subproperty of the return value of a method.

    So: there is an automation class which has a method Send815Request, this method returns an automation class instance of type IE815Response
    public IE815Response Send815Request(IE815Request request) 
    {
       ... 
    }
    
    Then the class IE815Response has a property called WSErrorDetails of type WSErrorDetails:
    public WsErrorDetails WSErrorDetails { get; set; }
    
    This WsErrorDetails class has a property FunctionalErrorCollection of type FunctionalErrorCollection:
    public FunctionalErrorCollection FunctionalErrorCollection { get; set; }
    
    And in the class FunctionalErrorCollection there is an indexer for retrieving the FunctionalError instances that have the problem:
    new public FunctionalError this[int index]
    {
      get { return (FunctionalError)base[index]; }
      set { base[index] = value; }
    }
    
  • Options
    veerleverbrveerleverbr Member Posts: 7
    I found the problem:

    The C/AL code tested first if the FunctionalErrorCollection was empty by testing if count > 0; this generated true, which is correct because there was one object in the collection. Next the object was retrieved using item(0). Although this works fine in the classic client, the RTC code doesn't seem to do this correct, I saw that using the Visual Studio debugger on the generated C# code. Therefore, all properties of the incorrectly retrieved object from the collection generated errors.

    In the .NET code, I modified my FunctionalErrorCollection so that it no longer inherits from ArrayList and I replaced the indexer with:
    List<FunctionalError> _list = new List<FunctionalError>();
    
    public FunctionalError Item(int index)
    {
       if (index >= 0 && index < _list.Count)
       {
          return _list[index];
       }
       return null;
    }
    
    public int Count
    {
       get
       {
          return _list.Count;
       }
    }
    

    Now it works like a charm.

    This is a bug in the RTC code though, the ArrayList with indexer should work!
Sign In or Register to comment.