unable to cast object of type ‘system.object ‘ to type ‘system.collections.IList’

I’m trying to retrieve information from a contract. Saving info works just fine and it communicates well but when I try to retrieve the info it give this error:
unable to cast object of type 'system.object' to type 'system.collections.IList'

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public async Task<string[]> GetAllPatientIdsAsync() {
var contract = _web3.Eth.GetContract(_abi, _contractAddress);
var getAllPatientIdsFunction = contract.GetFunction("getAllPatientIds");
try
{
var result = await getAllPatientIdsFunction.CallAsync<object>();
if (result is object[] objectArray)
{
string[] idsArray = objectArray.Select(x => x.ToString()).ToArray();
return idsArray;
}
else
{
MessageBox.Show($"Unexpected return type: {result.GetType()}.");
return null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
return null;
}
}
</code>
<code>public async Task<string[]> GetAllPatientIdsAsync() { var contract = _web3.Eth.GetContract(_abi, _contractAddress); var getAllPatientIdsFunction = contract.GetFunction("getAllPatientIds"); try { var result = await getAllPatientIdsFunction.CallAsync<object>(); if (result is object[] objectArray) { string[] idsArray = objectArray.Select(x => x.ToString()).ToArray(); return idsArray; } else { MessageBox.Show($"Unexpected return type: {result.GetType()}."); return null; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); return null; } } </code>
public async Task<string[]> GetAllPatientIdsAsync() {
    var contract = _web3.Eth.GetContract(_abi, _contractAddress);
    var getAllPatientIdsFunction = contract.GetFunction("getAllPatientIds");

    try
    {
        var result = await getAllPatientIdsFunction.CallAsync<object>();

        if (result is object[] objectArray)
        {
            string[] idsArray = objectArray.Select(x => x.ToString()).ToArray();
            return idsArray;
        }
        else
        {
            MessageBox.Show($"Unexpected return type: {result.GetType()}.");
            return null;
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error");
        return null;
    }
}

Here is the code of the Contract:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract PatientRecord {
struct Patient {
string id;
string name;
string medicalHistoryHash;
}
mapping(string => Patient) private patients;
string[] private patientIds; // Array to store patient IDs
// Event to log the addition of a new patient
event PatientAdded(string id, string name, string medicalHistoryHash);
// Function to add a new patient
function addPatient(
string memory _id,
string memory _name,
string memory _medicalHistoryHash
) public {
// Check if the patient already exists
require(bytes(patients[_id].id).length == 0, "Patient already exists");
// Add the patient to the mapping
patients[_id] = Patient(_id, _name, _medicalHistoryHash);
// Add the patient ID to the array
patientIds.push(_id);
// Emit the event
emit PatientAdded(_id, _name, _medicalHistoryHash);
}
// Function to retrieve a patient's information
function getPatient(string memory _id) public view returns (string memory, string memory) {
// Check if the patient exists
require(bytes(patients[_id].id).length != 0, "Patient not found");
// Retrieve and return the patient's information
Patient memory patient = patients[_id];
return (patient.name, patient.medicalHistoryHash);
}
// Function to update a patient's medical history
function updateMedicalHistory(string memory _id, string memory _newMedicalHistoryHash) public {
// Check if the patient exists
require(bytes(patients[_id].id).length != 0, "Patient not found");
// Update the patient's medical history
patients[_id].medicalHistoryHash = _newMedicalHistoryHash;
}
// Function to retrieve all patient IDs
function getAllPatientIds() public view returns (string[] memory) {
return patientIds;
}
}
</code>
<code>// SPDX-License-Identifier: MIT pragma solidity >=0.4.22 <0.9.0; contract PatientRecord { struct Patient { string id; string name; string medicalHistoryHash; } mapping(string => Patient) private patients; string[] private patientIds; // Array to store patient IDs // Event to log the addition of a new patient event PatientAdded(string id, string name, string medicalHistoryHash); // Function to add a new patient function addPatient( string memory _id, string memory _name, string memory _medicalHistoryHash ) public { // Check if the patient already exists require(bytes(patients[_id].id).length == 0, "Patient already exists"); // Add the patient to the mapping patients[_id] = Patient(_id, _name, _medicalHistoryHash); // Add the patient ID to the array patientIds.push(_id); // Emit the event emit PatientAdded(_id, _name, _medicalHistoryHash); } // Function to retrieve a patient's information function getPatient(string memory _id) public view returns (string memory, string memory) { // Check if the patient exists require(bytes(patients[_id].id).length != 0, "Patient not found"); // Retrieve and return the patient's information Patient memory patient = patients[_id]; return (patient.name, patient.medicalHistoryHash); } // Function to update a patient's medical history function updateMedicalHistory(string memory _id, string memory _newMedicalHistoryHash) public { // Check if the patient exists require(bytes(patients[_id].id).length != 0, "Patient not found"); // Update the patient's medical history patients[_id].medicalHistoryHash = _newMedicalHistoryHash; } // Function to retrieve all patient IDs function getAllPatientIds() public view returns (string[] memory) { return patientIds; } } </code>
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

contract PatientRecord {
    struct Patient {
        string id;
        string name;
        string medicalHistoryHash;
    }

    mapping(string => Patient) private patients;
    string[] private patientIds; // Array to store patient IDs

    // Event to log the addition of a new patient
    event PatientAdded(string id, string name, string medicalHistoryHash);

    // Function to add a new patient
    function addPatient(
        string memory _id, 
        string memory _name, 
        string memory _medicalHistoryHash
    ) public {
        // Check if the patient already exists
        require(bytes(patients[_id].id).length == 0, "Patient already exists");

        // Add the patient to the mapping
        patients[_id] = Patient(_id, _name, _medicalHistoryHash);
        
        // Add the patient ID to the array
        patientIds.push(_id);

        // Emit the event
        emit PatientAdded(_id, _name, _medicalHistoryHash);
    }

    // Function to retrieve a patient's information
    function getPatient(string memory _id) public view returns (string memory, string memory) {
        // Check if the patient exists
        require(bytes(patients[_id].id).length != 0, "Patient not found");
        // Retrieve and return the patient's information
        Patient memory patient = patients[_id];
        return (patient.name, patient.medicalHistoryHash);
    }

    // Function to update a patient's medical history
    function updateMedicalHistory(string memory _id, string memory _newMedicalHistoryHash) public {
        // Check if the patient exists
        require(bytes(patients[_id].id).length != 0, "Patient not found");

        // Update the patient's medical history
        patients[_id].medicalHistoryHash = _newMedicalHistoryHash;
    }

    // Function to retrieve all patient IDs
    function getAllPatientIds() public view returns (string[] memory) {
        return patientIds;
    }
}

I kept asking ChatGPT but it stopped giving the same error, I should be able to retrieve the String IDs in the list

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật