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)

Cast generic Object to class

(0) ShareShare
ReportReport
Posted on by

I am currently trying to cast a generic object to a specific class, with no luck yet.

Here is the scenario. I am receiving a generic object, and need to convert it to a specific type of a class. I tried the below, but none is working. Any ideas on how to make this work would be greatly appreciated.

class speicificClass()
{
str parm1, parm2;

public str parm1(str _parm1 = parm1)
{
parm1 = _parm1
return parm1
}

public str parm2(str _parm2 = parm2)
{
parm2 = _parm2
return parm2
}
}

Object genericClass;

SpecificClass specificClass;


//method 1 - cast generic to specific
specificClass = genericClass as SpecificClass();

//method 2
specificClass = genericClass;


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    SaverioT Profile Picture
    330 on at

    Try:

    specificClass = genericClass as SpecificClass;

    without parentesis ().

  • Matthew C Profile Picture
    on at

    Tried it but getting a null value on the specific class.

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    What's the actual type of object that you have in genericClass variable? It seems that it's not compatible with SpecificClass, therefore the cast is invalid.

  • SaverioT Profile Picture
    330 on at

    SpecificClass must extend generic class.

    This declaration is missing in the sample file that you given.

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
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans