Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidProgramException on compiling an expression that returns a record which implements IList #347

Closed
TFTomSun opened this issue Sep 8, 2022 · 4 comments
Assignees
Milestone

Comments

@TFTomSun
Copy link

TFTomSun commented Sep 8, 2022

I discovered an issue that only appears on linux (the official dotnet sdk docker container)

InvalidProgramException [0]: Common Language Runtime detected an invalid program.
at bool (ArrayClosure, MyNotifyA)
at Func FastExpressionCompiler.ExpressionCompiler+CurryClosureFuncs.Curry<C, R>(Func<C, R> f, C c)+(T1 t1) => { }
at TSource[] System.Linq.Enumerable+WhereEnumerableIterator.ToArray()
at IReadOnlyListRecord CustomCollectionExtensions.ToReadOnlyRecord(IEnumerable items)
at IReadOnlyListRecord (ArrayClosure, NotifyContainer<<>f__AnonymousType1<MyNotifyA, IObservableConcurrentCollection>>)

    internal sealed record ReadOnlyListRecord<T> : IReadOnlyListRecord<T>
    {
        public ReadOnlyListRecord(params T[] items) => Items = items.ToList().AsReadOnly();
        /// <summary>
        /// Gets or initializes the items in this collection.
        /// </summary>
        public IReadOnlyList<T> Items { get; }

        /// <inheritdoc />
        public IEnumerator<T> GetEnumerator()
        {
            return Items.GetEnumerator();
        }

        /// <inheritdoc />
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        /// <inheritdoc />
        public int Count
        {
            get { return Items.Count; }
        }

        /// <inheritdoc />
        public T this[int index] => Items[index];

        /// <inheritdoc />
        public override int GetHashCode()
        {
            int someHashValue = -234897289;
            foreach (var item in Items)
            {
                someHashValue = someHashValue ^ item.GetHashCode();
            }

            return someHashValue;
        }

        /// <inheritdoc />
        public bool Equals(ReadOnlyListRecord<T> other)
        {
            // create a proper equality method...
            if (other == null || other.Count != Count)
            {
                return false;
            }
            for (int i = 0; i < Count; i++)
            {
                if (!other[i].Equals(this[i]))
                {
                    return false;
                }
            }

            return true;
        }
    }

public static class Extensions
{
    public static IReadOnlyListRecord<T> ToReadOnlyRecord<T>(this IEnumerable<T> items) => new ReadOnlyListRecord<T>(items.ToArray());

}

expression

x => x.Value.collectionA.Where(i => i.Number1 % 2 == 0 || x.Value.model.Number2 == 0).ToReadOnlyRecord()
@dadhi
Copy link
Owner

dadhi commented Sep 8, 2022

What is the FEC version?

@TFTomSun
Copy link
Author

TFTomSun commented Sep 8, 2022

just realized, the same expression fails under net48 with the following exception:

> BadImageFormatException [0]: 
    Throw.OutOfBounds()
    MethodDebugInformationTableReader.GetSequencePoints(MethodDebugInformationHandle handle)
    StackTraceSymbols.GetSourceLineInfoWithoutCasAssert(string assemblyPath, IntPtr loadedPeAddress, int loadedPeSize, IntPtr inMemoryPdbAddress, int inMemoryPdbSize, int methodToken, int ilOffset, out string sourceFile, out int sourceLine, out int sourceColumn)
   

@TFTomSun
Copy link
Author

TFTomSun commented Sep 8, 2022

I use 3.3.3 ... should be the latest

dadhi added a commit that referenced this issue Sep 20, 2022
@dadhi
Copy link
Owner

dadhi commented Oct 1, 2022

@TFTomSun The late question on the issue, what is the type of x in x => x.Value.collectionA.Where(i => i.Number1 % 2 == 0 || x.Value.model.Number2 == 0).ToReadOnlyRecord() ?

If it is NotifyContainer<<>f__AnonymousType1<MyNotifyA, IObservableConcurrentCollection>, then how it is looking like?

dadhi added a commit that referenced this issue Oct 1, 2022
dadhi added a commit that referenced this issue Oct 2, 2022
dadhi added a commit that referenced this issue Oct 2, 2022
dadhi added a commit that referenced this issue Oct 2, 2022
added TryGetDebugClosureNestedLambdaOrConstant extension method
dadhi added a commit that referenced this issue Oct 3, 2022
@dadhi dadhi closed this as completed Nov 29, 2022
@dadhi dadhi self-assigned this Nov 29, 2022
@dadhi dadhi added this to the 3.3.4 milestone Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants