.NET Google Workspace API getting error CS0266

49 Views Asked by At

I am generating a user and populating them into our Google Workspace environment but I cannot seem to get the CustomSchemas to work. I have fiddled around with a few different ways to format it but I still cannot get it to work properly.

userGoogleUserWithData = new User()
{
    PrimaryEmail = userEmail,
    Password = generatedPassword,
    Name = new UserName
    {
        GivenName = givenName,
        FamilyName = familyName
    },
    ChangePasswordAtNextLogin = true,
    OrgUnitPath = "/",
    Suspended = false,
    Relations = new List<UserRelation>
    {
        new UserRelation { Type = "manager", Value = googleData.manager } // Set the manager's email
    },
    Addresses = new List<UserAddress>
    {
        new UserAddress
        {
            Type = "work",
            Formatted = googleData.locationAddress,
            Locality = myBranch.branchCity,
            Region = myBranch.branchState,
            PostalCode = myBranch.branchZip,
            Country = myBranch.branchCountry
        }
    },
    Organizations = new List<UserOrganization>
    {
        new UserOrganization
        {
            Title = googleData.jobTitle,
            Primary = true,
            Department = googleData.department,
            CostCenter = googleData.costCenter,
            Description = "user",
            Name = "Test Company"
        }
    },
    CustomSchemas = new Dictionary<string, object>
    {
        ["Custom Field Testing"] = new Dictionary<string, string>
        {
            ["blah text"] = "Test Value"
        }
    }
};
service.Users.Insert(userGoogleUserWithData).Execute();

Custom Field Testing and blah text should be the key values in my workspace. am I getting the formatting wrong? It continues to give me an Error CS0266 no matter how I set it up.

Full error:

Severity Code Description Project File Line Suppression State Details Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.Dictionary<string, object>' to 'System.Collections.Generic.IDictionary<string, System.Collections.Generic.IDictionary<string, object>>'. An explicit conversion exists (are you missing a cast?) 277 Active

Line 277 is:

CustomSchemas = new Dictionary<string, object>
1

There are 1 best solutions below

1
Guru Stron On BEST ANSWER

I would argue that error is pretty clear - you have type mismatch, you are trying to assign instance of new Dictionary<string, object> to IDictionary<string, IDictionary<string, object>>, so try the followwing:

CustomSchemas = new Dictionary<string, IDictionary<string, object>>
{
    ["Custom Field Testing"] = new Dictionary<string, object>
    {
        ["blah text"] = "Test Value"
    }
}