question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Collection was modified; enumeration operation may not execute" thrown by await FastTextLanguageDetector.FromStoreAsync in .NET Core 3.1

See original GitHub issue

The following code throws an InvalidOperationException with the message “Collection was modified; enumeration operation may not execute.” on the line that calls await FastTextLanguageDetector.FromStoreAsync when the application targets .NET Core 3.1.

However, it works fine when targeting .NET 5!

using System;
using System.IO;
using System.Threading.Tasks;
using Catalyst;
using Catalyst.Models;
using Mosaik.Core;
using Version = Mosaik.Core.Version;

namespace CatalystSimilarityExample
{
    class Program
    {
        static async Task Main()
        {
            const string modelFolderName = "catalyst-models";
            Storage.Current = new OnlineRepositoryStorage(new DiskStorage(modelFolderName));
            var languageDetector = await FastTextLanguageDetector.FromStoreAsync(
                Language.Any,
                Version.Latest,
                ""
            );
        }
    }
}

The stack trace shows this:

at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
at System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
at Catalyst.Models.FastText.CompactSupervisedModel()
at Catalyst.Models.FastTextLanguageDetector.<FromStoreAsync>d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at CatalystSimilarityExample.Program.<Main>d__0.MoveNext() in C:\\Users\\Dan\\source\\repos\\ParallelLinqExample\\CatalystSimilarityExample\\Program.cs:line 17

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gillonbacommented, Mar 24, 2021

Also, in my testing of the same code the LanguageDetector was only 56.8% accurate. For example code, not good! I run the samples to decide whether I want to use the library for real and that is somewhat less than inspiring. Maybe I should just bite the bullet call spaCy scripts from my application? It would be much better to use pure .Net but only if it works. Maybe I need to look into upgrading to .Net 5?

0reactions
ProductiveRagecommented, Apr 2, 2021

@ProductiveRage fixed the bug with loading the FT model - was a recent memory optimization added to the FT model that broke loading classifier models from disk.

Sorry, @theolivenbaum, I missed this update somehow - can confirm that I’ve tested with 3.1 and it works fine now! I’m closing this issue even though there seems to be a question from @gillonba about detection accuracy… I suspect that that should be a separate issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Collection was modified; enumeration operation may not ...
Obviuosly, your do something code is trying to modify the collection. It's generally a bad idea to modify the collection while iterating on...
Read more >
Error : Collection was modified; enumeration operation ...
Error : Destination array was not long enough. Check the destination index, length, and the array's lower bounds. Parameter name: ...
Read more >
Collection was modified; enumeration operation may not ...
This error can happen in two scenarios: You're looping over the collection in a foreach loop and modifying it (add/removing) in the same ......
Read more >
NET: Collection was modified; enumeration operation may not ...
For discounts on courses I offer, see the 2020 trailer video of this YouTube channel - https://www.youtube.com/watch?v=RJyHb45efUs.
Read more >
catalyst - bytemeta
"Collection was modified; enumeration operation may not execute" thrown by await FastTextLanguageDetector.FromStoreAsync in .NET Core 3.1. dgerding.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found