Skip to main content

Notifications

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 81

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.

  • Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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.

  • akshi Profile Picture
    akshi 81 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    Hi Martin,

    I haven't set anything in the FormDatasource properties.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,868 Most Valuable Professional on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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.

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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.

  • akshi Profile Picture
    akshi 81 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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
    akshi 81 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: error CS0120: An object reference is required for the non-static field, method, or property 'FormName.FormDatasource'

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,031 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,868 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans