C
C#4mo ago
microlith57

✅ ImmutableArray<T>.Contains(T, IEqualityComparer<T>) exists in one thread, but not another

this is a very confusing problem and i have not had any luck producing a minimal working example; i'm happy to provide any kind of info. i'm making a mod for a game (Celeste) that involves compiling and loading C# source at runtime; i'm using Microsoft.CodeAnalysis.CSharp for this. i already have a standalone prototype of that process and am trying to convert it into a mod. for some reason, only in the mod version, when i call CSharpCompilation.Emit , an error is thrown in the worker thread:
System.MissingMethodException: Method not found: 'Boolean System.Collections.Immutable.ImmutableArray`1.Contains(!0, System.Collections.Generic.IEqualityComparer`1<!0>)'.
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ComputeInterfaceImplementations(BindingDiagnosticBag diagnostics, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetSynthesizedExplicitImplementations(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ForceComplete(SourceLocation locationOpt, Predicate`1 filter, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbol.ForceCompleteMemberConditionally(SourceLocation locationOpt, Predicate`1 filter, Symbol member, CancellationToken cancellationToken)
at Roslyn.Utilities.RoslynParallel.<>c__DisplayClass1_0.<For>g__errorHandlingBody|0(Int32 i)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
System.MissingMethodException: Method not found: 'Boolean System.Collections.Immutable.ImmutableArray`1.Contains(!0, System.Collections.Generic.IEqualityComparer`1<!0>)'.
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ComputeInterfaceImplementations(BindingDiagnosticBag diagnostics, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.GetSynthesizedExplicitImplementations(CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol.ForceComplete(SourceLocation locationOpt, Predicate`1 filter, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.CSharp.Symbol.ForceCompleteMemberConditionally(SourceLocation locationOpt, Predicate`1 filter, Symbol member, CancellationToken cancellationToken)
at Roslyn.Utilities.RoslynParallel.<>c__DisplayClass1_0.<For>g__errorHandlingBody|0(Int32 i)
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion)
6 Replies
microlith57
microlith57OP4mo ago
i then noticed that when i attach a debugger and test this method in the main thread it exists:
System.Collections.Immutable.ImmutableArray.Create("Red", "Green", "Blue").Contains("Yellow", System.Collections.Generic.EqualityComparer<string>.Default);
// -> false
System.Collections.Immutable.ImmutableArray.Create("Red", "Green", "Blue").Contains("Yellow", System.Collections.Generic.EqualityComparer<string>.Default);
// -> false
but, pausing on that exception in the worker thread, the same method no longer exists:
System.Collections.Immutable.ImmutableArray.Create("Red", "Green", "Blue").Contains("Yellow", System.Collections.Generic.EqualityComparer<string>.Default);
// -> error CS1501: No overload for method 'Contains' takes 2 arguments
System.Collections.Immutable.ImmutableArray.Create("Red", "Green", "Blue").Contains("Yellow", System.Collections.Generic.EqualityComparer<string>.Default);
// -> error CS1501: No overload for method 'Contains' takes 2 arguments
i have verified that these ImmutableArray types are both from the same System.Collections.Immutable.dll path, so i don't understand how the debugger / runtime can find the method in one thread and not another. i believe the Contains call throwing the exception is this one, though i'm not familiar enough with roslyn's structure to be sure
reflectronic
reflectronic4mo ago
what is AssemblyLoadContext.All.Count()
333fred
333fred4mo ago
I cannot explain your threading thing, but if you're seeing that exception in general, you've mixed your versions of roslyn and its dependencies In particular, I believe that API was added in System.Collections.Immutable 8.0.0, which means that you're using a very old version of SCI, with presumably a modern version of roslyn
microlith57
microlith57OP4mo ago
thanks very much, downgrading roslyn to a version compatible with the System.Collections.Immutable i'm using worked! i guess the threading thing threw me off the more mundane cause haha is there some way to mark this thread resolved?
333fred
333fred4mo ago
$close
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server