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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Declare subclass in dll and call the methods from X++

(0) ShareShare
ReportReport
Posted on by 30

Hi experts,

I got a dll with two classes in inheritance relation, like below: 

namespace Test

{

public class A

{

public class B

{

public string bString;

public string bMethod()

{

return bString;

}

}

}

}

when I add this dll to AX references and try to using it, class A is the only thing I can get, I can't declare B so that can't call method bMethod. 

Is possible to declare class B and call method bMethod? if yes, how? Thanks for your help.

Best regards;

Daniel 

*This post is locked for comments

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

    This isn't inheritance. Class B doesn't inherit from Class A; it's nested inside it (see Nested Types (C# Programming Guide)).

    Try new Test.ClassA.ClassB() to instantiate the nested type, but I don't know if .NET Interop supports it.

  • DanielBai Profile Picture
    30 on at

    Thanks Martin.

    Yes, you are right, it's not inheritance.

    I tried as your suggestion, but it's not working with compile error "Test.ClassA.ClassB is not class".

  • Verified answer
    Martin Dráb Profile Picture
    239,385 Most Valuable Professional on at

    All right, I'm not surprised that it's not supported.

    A few suggestions:

    • If you can, get rid of the nested class.
    • If you can't, create a custom library which will do the instantiation. Consider create a proxy hiding the nested classes.
    • Alternatively use System.Activator to create the instance (I think it should be Activator.CreateInstance('Test.ClassA+TestB')).

    Note that even if you create an instance, you probably won't be able to declare variables of this type and therefore you'll get no compile-time type control, code completion and so on. This would be solved by a proxy class.

  • DanielBai Profile Picture
    30 on at

    Appreciate it, it's worked.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans