web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Consuming C# classes from the Collections.Generic namespace

(0) ShareShare
ReportReport
Posted on by 545

I'm writing some code related to service bus in X++.

In part of my code I need to read BrokeredMessage.Properties (https://docs.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.brokeredmessage.properties?view=azure-dotnet) which is of type System.Collections.Generic.IDictionary<string,object>

Within X++ I can reference this as System.Collections.Generic.IDictionary`2 however the ` creates a compilation error.

Any idea how I can go about this?  I currently am using var, but then I do not get the intellisense.

 

I have the same question (0)
  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Hi Normbert, I moved your question from Dynamics 365 General Forum here to the AX forum, but I don't which version you're talking about and whether it shouldn't actually be in an F&O forum. Please clarify.

    Your options depend on the version.

  • nspiteri Profile Picture
    545 on at

    I left the version part open on purpose as I'm curious how it would be done both in F&O and in Ax.  Most importantly in F&O though.

  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    In F&O, simply use var as the type name:

    var properties = message.Properties;

    But you can't do that in older versions. If you need a solution for F&O, we're done. If you need a solutions for older versions, this is completely useless to you and we'll need to discuss other ways.

  • nspiteri Profile Picture
    545 on at

    Thanks for the information.

    I suspected it couldn't be done in older versions but I wanted confirmation.

    Regarding F&O, as I mentioned, I have successfully used var but it makes it an object type so I don't get Intellisense or compile time checks.. I am interested to know if there is an alternative.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    That's not correct - var doesn't mean weakly typing (as with anytype or so) and you'll get compile-time checking. It's true that IntelliSense often have a problem with it. Using var means that the type is detected by compiler, not that the type is unknown. Could you test it once more, please? For example, try to compile this:

    var properties = message.Properties;
    properties.Abcdefg();

    The compiler should tell you that no such a method exists.

    I'm not saying that you can't work with generic collections in older versions, but you can't do it in this way. My recommendation is using non-generic interfaces  there, such as IEnumerable if you want to iterate the collection. You can also declare the type is CLRObject, but then you really don't get any compile-time checking.

  • nspiteri Profile Picture
    545 on at

    Hi Martin,

    you're absolutely right about this.  The error does occur at compile time.  I was under the wrong impression that since Intellisense half works (some methods show up while others don't), that var, in Dynamics, was choosing a more generic type.

    Thanks for pointing that out.  I think its another note of improvement for the guys working on the IDE.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 663 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 540 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 348 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans