Skip to content

Connect.GetDomains throw System.BadImageFormatException #4

Description

@WenceyWang
public List<Domain> GetDomains(virConnectListAllDomainsFlags flags = default)
{
    int result = Libvirt.virConnectListAllDomains(_conn, out IntPtr ptrDomains, flags);

    ThrowExceptionOnError(result);

    List<Domain> domains = new List<Domain>();

    for (int i = 0; i < result; i++)
    {
        IntPtr ptrDomain = Marshal.ReadIntPtr(ptrDomains, i * IntPtr.Size);
        domains.Add(new Domain(_conn, ptrDomain));
    }

    Marshal.FreeHGlobal(ptrDomains);

    return domains;
}

Marshal.FreeHGlobal(ptrDomains); calls Kernel32.LocalFree instead of free in vcrt on Windows and cause System.BadImageFormatException

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions