none
Evaluation of method System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable`1<string>) calls into native method System.Globalization.TextInfo.InternalGetCaseInsHash(System.IntPtr, System.IntPtr, string, string, bool, long). RRS feed

  • Question

  • I tried to execute relatively simply command in Immediate window

    someIds = SomeObject.Items.Select(i => i.Code).ToList();

    getting exception

    Evaluation of method System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable`1<string>) calls into native
    method System.Globalization.TextInfo.InternalGetCaseInsHash(System.IntPtr, System.IntPtr, string, string, bool, long).
    Evaluation of native methods in this context is not supported.

    Similarly.

    someIds = SomeObject.Items.Select(i => i.Code).ToArray();

    Evaluation of method System.Linq.Enumerable.ToArray(System.Collections.Generic.IEnumerable`1<string>) calls into native
    method System.Globalization.TextInfo.InternalGetCaseInsHash(System.IntPtr, System.IntPtr, string, string, bool, long).
    Evaluation of native methods in this context is not supported.

    It’s really surprising because code

    someIds = new List<string>{ SomeObject.Items.First().Code };

    works perfectly fine.

    Am I doing something wrong? The Items object is some IList<T> holding not complex objects that have Code initialized.

    • Edited by User919 Tuesday, September 24, 2019 10:30 AM
    Thursday, September 19, 2019 12:37 PM

Answers

  • Hi User919,

    Sorry for my mistakes.

    Yes, I could also reproduce this issue on my side. As my understanding, "ToList()" will force immediate query evaluation then return a list. It seems that there are some conflicts about immediate query function between them. 

    And also, I have report it to product team, please be patient to wait for the response of product team experts. Thank you for understanding.

    The link:

    https://developercommunity.visualstudio.com/content/problem/746538/systemlinqenumerabletolist-could-not-work-in-imemd.html

    Cheers,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by User919 Thursday, September 26, 2019 7:43 AM
    Wednesday, September 25, 2019 3:52 AM

All replies

  • Hi User919,

    Welcome to MSDN forum.

    The "ToList()" will forces immediate query evaluation and returns a List<T> that contains the query results. The "ToArray()" is similar with it.

    And the "new List<>" will initializes a new instance of the List<T> class that is empty, then add your objects in it.

    So the difference depends more on your objects, could you share your one object sample here?

    BTW, if the object is a class, maybe you could refer this thread: https://stackoverflow.com/a/2774121

    Look forward to your feedback.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, September 20, 2019 2:14 AM
  • Hi User919,

    Welcome to MSDN forum.

    The "ToList()" will forces immediate query evaluation…

    Hi Dylan,

    thank you for assistance. I prepared some minimal example. The exception is different but the concept persists.

    Let use .NET Framework 4.7.2  console app and VS 2017E v 15.9.14.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace InternalGetCaseInsHash
    {
        class Program
        {
            static void Main(string[] args)
            {
                var list = new List<string>();
                var someObject = new SomeObject();
            }
    
            public class SomeObject
            {
                public IList<someitem>Items => Enumerable.Range(0, 3).Select(x => new SomeItem()).ToList();
            }
    
            public class SomeItem
            {
                public string Code => DateTime.Now.Ticks.ToString();
            }
        }
    }
    

    Immediate window commands and results

    someObject.Items
    Count = 3
        [0]: {InternalGetCaseInsHash.Program.SomeItem}
        [1]: {InternalGetCaseInsHash.Program.SomeItem}
        [2]: {InternalGetCaseInsHash.Program.SomeItem}
    	
    list = someObject.Items.Select(i => i.Code).ToList()
    Evaluation of method System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable`1<string>) calls into native method System.DateTime.GetSystemTimeWithLeapSecondsHandling(System.DateTime+FullSystemTime&). Evaluation of native methods in this context is not supported.
    
    list = new List<string>{ someObject.Items[0].Code }
    Count = 1
        [0]: "637045997663034699"
    

    You can see there is some issue with LINQ execution.

    Solution 7z archive. Solution zip archive.


    • Edited by User919 Friday, September 20, 2019 4:40 PM
    Friday, September 20, 2019 4:22 PM
  • Hi User919,

    Sorry for delay in reply.

    I have tried this sample here. It could work here.


    So please try to update your visual studio to latest version, then check if it could work on your side.

    Look forward to your feedback.

    Cheers,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, September 24, 2019 9:37 AM
  • Hi User919,

    Sorry for delay in reply.

    I have tried this sample here …

    Hi Dylan,

    delay is not mattered.

    Issue is regard Immediate window (as states 1st sentence in 1st post).



    Not about Autos window.
    • Edited by User919 Tuesday, September 24, 2019 10:30 AM
    Tuesday, September 24, 2019 10:27 AM
  • Hi User919,

    Sorry for my mistakes.

    Yes, I could also reproduce this issue on my side. As my understanding, "ToList()" will force immediate query evaluation then return a list. It seems that there are some conflicts about immediate query function between them. 

    And also, I have report it to product team, please be patient to wait for the response of product team experts. Thank you for understanding.

    The link:

    https://developercommunity.visualstudio.com/content/problem/746538/systemlinqenumerabletolist-could-not-work-in-imemd.html

    Cheers,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by User919 Thursday, September 26, 2019 7:43 AM
    Wednesday, September 25, 2019 3:52 AM
  • Hi User919,

    Sorry for my mistakes.

    Yes, I could also reproduce this issue on my side. As my understanding, "ToList()" will force immediate query evaluation then return a list…

    Hi Dylan,

    as I started few days ago foreboding that you’ll not be able to help me I reported the issue also – System.Linq.Enumerable.ToList(System.Collections.Generic.IEnumerable`1) calls into native method. The page is reporting it was yesterday but it was on 24th in the morning.

    I found your issue nicer. 🤔


    • Edited by User919 Thursday, September 26, 2019 7:44 AM
    Thursday, September 26, 2019 7:43 AM