I used VS2019 to write C# project in Windows7. There is a error when I tried to compile the project:
An object reference is required for the non-static field, method, or property
'ViewerController.curLSUnits'
When I tried to used some recommended method from other similar questions, that is, add"static" to the definition of curLSUnits, new error occurs(Member 'ViewerController.curLSUnits' cannot be accessed with an instance reference; qualify it with a type name instead ImageExplorerServer), seems like I could not add "static".
What should I do to fix this "An object reference is required for the non-static field, method, or property 'ViewerController.curLSUnits' " problem?
viewcontroller.cs:
public UnitData[] curLSUnits;
public static void SaveToFile(int exportFileIndex, string argDBpath,
DataTable dt, int currentRow,int
m_IESTrayXTrayYValueEqualToTrayColTrayRow,int m_ExportDefectWithRedRec,
BackgroundWorker bgw = null)
{
try
{
if (exportFileIndex == 2)
{
string pathExptRpt = Path.GetDirectoryName(argDBpath) +
"\\ExportFolder\\" + Path.GetFileNameWithoutExtension(argDBpath) +
".csv";
ExportRpt.WriteDefToCsv(bgw, pathExptRpt, dt,
exportFileIndex, currentRow,
m_IESTrayXTrayYValueEqualToTrayColTrayRow,
m_ExportDefectWithRedRec, curLSUnits); //WY200619
}
else
{
string pathExptRpt = Path.GetDirectoryName(argDBpath) + "\\"
+ Path.GetFileNameWithoutExtension(argDBpath) + ".xlsx";
ExportRpt.WriteDefToExcel(bgw, pathExptRpt, dt,
exportFileIndex, currentRow,
m_IESTrayXTrayYValueEqualToTrayColTrayRow,
m_ExportDefectWithRedRec);
}
}
catch (System.Exception ex)
{
debug.OutputDebugLogString("[IES] Temp debug log (SaveToFile):"
+ex.ToString() + Environment.NewLine);
}
}
exportRPT.cs:
public static void WriteDefToCsv(BackgroundWorker bgw, string
pathSaveFile, DataTable dtDefDetails, int ExportFileIndex, int
currentRow,
int IESTrayXTrayYValueEqualToTrayColTrayRow, int ExportDefectWithRedRec,
UnitData[] curLSUnits)
{
try
{
System.IO.Directory.CreateDirectory(Path.GetDirectoryName(pathSaveFile));
var csv = new StringBuilder();
//Write Headers
string Headers;
SetDefectColumnTitile(out Headers);
csv.AppendLine(Headers);
......