Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:27+00:00 2026-05-31T02:34:27+00:00

I need to pass a variable of type IDictionary<Guid, IEnumerable<Guid>> into a method. When

  • 0

I need to pass a variable of type IDictionary<Guid, IEnumerable<Guid>> into a method. When I use the following code:

var userGroupDictionary = _selectedUsers.ToDictionary(u => u.UserGuid, u => u.GroupUsers.Select(gu => gu.Group.GroupGuid).ToList());

I get the following error:

cannot convert from System.Collections.Generic.Dictionary<System.Guid,System.Collections.Generic.List<System.Guid>>' to 'System.Collections.Generic.IDictionary<System.Guid,System.Collections.Generic.IEnumerable<System.Guid>>'

When I iterate through my collection it works however:

var userGroupDictionary = new Dictionary<Guid, IEnumerable<Guid>>();
foreach (var user in _selectedUsers.Where(user => !userGroupDictionary.ContainsKey(user.UserGuid)))
{
    userGroupDictionary.Add(user.UserGuid, user.GroupUsers.Select(gu => gu.Group.GroupGuid).ToList());
}

Any ideas what’s going on? Is the compiler unable to tell that Dictionary<Guid, List<Guid>> satisfies IDictionary<Guid, IEnumerable<Guid>>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:34:28+00:00Added an answer on May 31, 2026 at 2:34 am

    The problem is that type inference is returning a Dictionary<Guid, List<Guid>>, which is the wrong type for the method you want to call. There’s a bit more to it than that, but it involves a type variance discussion. You can solve the problem with the AsEnumerable extension:

    var userGroupDictionary = _selectedUsers
        .ToDictionary(
            u => u.UserGuid,
            u => u.GroupUsers.Select(gu => gu.Group.GroupGuid).ToList().AsEnumerable());
    

    …or you can do a simple cast, as in the following:

    var userGroupDictionary = _selectedUsers
        .ToDictionary(
            u => u.UserGuid,
            u => (IEnumerable<Guid>)u.GroupUsers.Select(gu => gu.Group.GroupGuid).ToList());
    

    If you merely omit the ToList() as others have recommended, the type inference will indeed render the type you expect, but the IEnumerable returned will have deferred-execution which may or may not be an issue for you. Leaving ToList in there but doing a cast of sorts will immediately evaluate the items instead of lazily evaluating them at the time of iteration.

    For more detail on deferred execution, see the “laziness” (think lazy-evaluation) section of Jon Skeet’s Edulinq series, part 44

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pass a variable in dispatcher tag... for instance var google:EventName =
I need to know the simplest method to pass variable from custom module to
I need to pass a JavaScript Array variable to a code-behind file and access
I need to pass a regex substitution as a variable: sub proc { my
I need to pass data to a variable in my master page each time
I need to pass an array from JavaScript to a page method in C#.
I need to pass audio data into a 3rd party system as a 16bit
In the previous versions of Delphi, the following code: var InBuf: array[1..45] of Byte;
I have the following code: public void DeleteAccountsForMonth(int year, int month) { var result
I often come across situations when I need to use the same variable but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.