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, ...
Suggested Answer

error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

(0) ShareShare
ReportReport
Posted on by 152

Hello Experts,

The execution result is as expected, but the title error appears when debugging.
How can I avoid this compilation error?

Designed as follow.
There are a string control, an OK button and a Grid on a form.
Select a value in the string control and press the OK button to display the processing result in the Grid.

It is implemented as below.
1.override form’s init() method and initialize another tempDB buffer of the same type and link its physical instance to the current data source buffer.
2. I created a method in the form method that inserts data into a TempDB table whose table type is TempDB.
3. After pressing the OK button, get the form's string controls and call the PopulatesRecords method to insert data into the TempDB table. Then link the returned TemTable to the form data source.
4.The form's data source is set to a TempDB table.

The following is code.

public class TestSearchEnumForm extends FormRun
{
public void init()
{
TestInfoTemp tempTable;
super();
TestEnumName testEnumName = EnumName.text();
delete_from tempTable;
tempTable = element.populateRecords(testEnumName);
TestInfoTemp.linkPhysicalTableInstance(tempTable);
}

public TestEnumInfoTemp populateRecords(TestEnumName _testEnumName)
{
TestInfoTemp tempTable;
if (_testEnumName)
{
delete_from tempTable;
ttsbegin;
tempTable.field1 = text1;
tempTable.field2 = text2;
tempTable.insert();
}
return tempTable;
}

[Control("CommandButton")]
class OKCommandButton
{
/// 
///
/// 
public void clicked()
{
TestEnumInfoTemp tempTable;
super();
// get value from form string control.
TestEnumName testEnumName = EnumName.text();
DictEnum dictEnum = new DictEnum(enumName2Id(testEnumName));
if (dictEnum)
{
// Insert data to TempDB table.
tempTable = element.populateRecords(testEnumName);
delete_from TestEnumInfoTemp;
// TestEnumInfoTemp is the form datasource whose table type is TempDB.
TestEnumInfoTemp.linkPhysicalTableInstance(tempTable);
}

}

}
}

Any advice would be greatly appreciated.

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi akshi,

    Are you saying that you are getting a compile time error while building the project?

    On line number 39 what does this line "if(dictEnum)" means?

    Thanks,

    Girish S.

  • akshi Profile Picture
    152 on at

    Hi Girish,

    I mean Debugging error. There is no error when building the project.

    Sorry, I added the 39 line for "if(dictEnum)" .

    Thanks.

  • GirishS Profile Picture
    27,827 Moderator on at

    While debugging exactly at what line error is throwing?

    Without debugging does the whole process run without any issues?

    Thanks,

    Girish S.

  • akshi Profile Picture
    152 on at

    The error that occurs during debugging is line 46.

    Yes, without debugging, the whole process runs fine.

    I'm getting the expected results.

    I posted a question because I was worried that an error had occurred during debugging.

    following is debugging error.

    4670.error.jpg

    But, Microsoft.Dynamics.Ax.Xpp.Common.linkPhysicalTableInstance returned in Local tab is True.

    linkPhysicalTableInstance-returned.jpg

    Should I ignore this error?

    Thanks.

  • GirishS Profile Picture
    27,827 Moderator on at

    I think this is not the run time or compile time error. It's related to the debugger. Also, TestEnumInfoTemp is the DataSource name, and it won't have value at the debugger watch window.

    So, my suggestion will be ignoring this error.

    Thanks,

    Girish S.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    If requirement working without any issue, then probably you can ignore debugging issue.

    If you want to learn more on this error, check this thread

    community.dynamics.com/.../debug-watch-not-showing-value-an-object-reference-is-required-for-the-non-static-field

  • Suggested answer
    Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    You're looking at the Watch window. There you seem to have an expression that can't be meaningfully evaluated in the current method. It seems that you want to display the value of FormDatasource property of FormName object, but no FormName object exists there.

  • akshi Profile Picture
    152 on at

    Hi Martin,

    I haven't set anything in the FormDatasource properties.

  • GirishS Profile Picture
    27,827 Moderator on at

    As I already told you cannot see the current record for the FormDataSource buffer and also ignore this kind of error as it will not affect your process.

    Thanks,

    Girish S.

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

    Sure, this has absolutely nothing to do with data source properties. It's all about the Watch window in debugger, which is used for a quick access to variables that you're interested in.

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans