Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

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

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Invalid token "=" when setting a property value in a c# class from x++ class

    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. :-)

  • Verified answer
    DanAx Profile Picture
    DanAx on at
    RE: Set a property value in a c# class from x++ class

    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;

    }

    }

  • DanAx Profile Picture
    DanAx on at
    RE: Set a property value in a c# class from x++ class

    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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Set a property value in a c# class from x++ class

    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.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans