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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Invalid token "=" when setting a property value in a c# class from x++ class

(0) ShareShare
ReportReport
Posted on by

I know there's a simple answer, I've probably read it already but it's been a long day and I'm tired.  Thanks in advance.

I have an azure D365 dev machine procured through LCS.

I have a c# class library called MyCSharpProj in my solution with one class

 public class x
 {
        public bool boolVal { get; set; }

 }

I've added a reference to the project in my solution from my "Dynamics 365 for Operations" "Operations Project"

I have a class in the operations project and the following method

public void test()
{
        MyCSharpProj.x testVar = new MyCSharpProj.x();
        testVar.boolVal = true; // this gives an error ' Invalid token "=" '
}

What is the correct way to be able to set the value from the c# class?

*This post is locked for comments

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

    Your code looks fine and it also compiles without any problem, if I try it in my system.
    It's interesting that the compiler doesn't complain about types, members or so; it fails in a much earlier phase, when it fails to recognize the token "=". Don't you have, by any chance, another Unicode character that looks like the equals sign, but it's technically something else? For example, ᐀ is "Canadian syllabics hyphen", not the equals sign.

  • DanAx Profile Picture
    on at

    MyCSharpProj.x testVar = new MyCSharpProj.x(); works
    testVar.boolVal = true; Doesn't work

    I can't believe there are any Unicode issues, but thank you so much for taking a stab, this is a weird one.

    As a test, I 've added a new c# class lib and referenced it with that code and it works for me as well.  I'm going to start adding all of the pieces from my existing lib into  the new one incrementally and see where it breaks, if it breaks.  I'll let you know what the result is.

  • Verified answer
    DanAx Profile Picture
    on at

    Resolved, my problem is that I have a c# class that exposes another class as a member. Apologies, I was not totally honest when I gave my initial example, I was trying to simplify it so as not to put a bunch of code into the example.  Consider the following code

    C#

     namespace Ax365InvalidTokenTestClassLibrary

    {

    public class X

    {

    public bool BoolPropertyMember { get; set; }

    }

    public class Y

    {

    public bool BoolPropertyMember { get; set; }

    }

    public class Z

    { 

    public Y y { get; set; }

    public X x { get; set; }

    }

    public class a

    {

    public void test()

    {

    Z z = new Z();

    // works fine here

    z.y.BoolPropertyMember = true;

    }

    }

    }

    X++

    class Class1

    {

    public void test()

    {

    Ax365InvalidTokenTestClassLibrary.Z z = new Ax365InvalidTokenTestClassLibrary.Z();

    //not fine here, this is an error : Invalid token "="

    z.x.BoolPropertyMember=true;

    //But this works

    Ax365InvalidTokenTestClassLibrary.X x = z.x;

    x.BoolPropertyMember=true;

    }

    }

  • Martin Dráb Profile Picture
    240,361 Most Valuable Professional on at

    Aha, thank you for the update.

    .NET Interop from X++ is getting better with every version, but it still has quite a few limitations. It will be great if you push for improvements internally. :-)

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans