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

ArgumentOutOfRangeException in RssDictionarySample #38

Open
ttustonic opened this issue Apr 14, 2020 · 11 comments
Open

ArgumentOutOfRangeException in RssDictionarySample #38

ttustonic opened this issue Apr 14, 2020 · 11 comments

Comments

@ttustonic
Copy link

Hello
I'm trying to run RssDictionarySample, but I get the ArgumentOutOfRangeException in line 49, when creating a new PersistentDictionary.

Unhandled Exception: System.TypeInitializationException: The type initializer for 'RssDictionarySample.TrivialRssReader' threw an exception. ---> System.ArgumentOutOfRangeException: Not supported for SetColumn Parameter name: TColumn Actual value was RssDictionarySample.RssFeedData.

it seems that ESENTCOLLECTIONS_SUPPORTS_SERIALIZATION is not defined, so how do I use a custom struct for a PersistentDictionary value?

@speed2048
Copy link

I am having the same issue, Is there any solution for this... I looked at the source code, to complicate for me to figure out why :)

@speed2048
Copy link

Okay I found out.... The following link explains why....

https://github.com/microsoft/ManagedEsent/releases

Would suggest to the owners of this repository to remove any examples that no longer work.... I am going to try and compile with ESENTCOLLECTIONS_SUPPORTS_SERIALIZATION defined to see how far I get..

@speed2048
Copy link

Forget using this if you want to to use .net core > 2.0. Found this that prevents its usage.

dotnet/runtime#23169

Darn all I want is a serializable Dictionary<int, T>. The two I have found don't work...

@ttustonic
Copy link
Author

You can serialize your T objects to JSON and use as a string in Dictionary<int, string>.

@speed2048
Copy link

speed2048 commented Jul 9, 2020

That what I am doing.... To bad ManagedEsent is not very useful now.

Thx...

@ttustonic
Copy link
Author

ttustonic commented Jul 10, 2020

Hm, I'm using it to hold a huge taxonomy database/dictionary and it works quite nice.
I serialize objects to Json string, convert to byte[] and use in a PersistentDictionary with PersistentBlob value.
PersistentDictionary<TKey, PersistentBlob> _dictionary

But, yes, it would be nice to remove samples that does not work, and create samples that do.

@speed2048
Copy link

I tried what you suggested but running into this issue. dotnet/runtime#23169.

It dies on this line of code..
var dictionary = new PersistentDictionary<int, PersistentBlob>("file-queue-2");

Any help would be appreciated...

@ttustonic
Copy link
Author

Here's a working example. It creates a PersistentDictionary in the folder dest and every time you run the program it adds a new Test object and dumps previously added one.

    class Test
    {
            public int Id { get; set; }
            public string Name { get; set; }
    } 

    static async Task Main(string[] args)
    {
        var dic = new PersistentDictionary<int, PersistentBlob>("dest");

        int max = 0;
        if (dic.Keys.Count > 0)
            max = dic.Keys.Max();

        if (dic.TryGetValue(max, out var blob))
        {
            var bytes = blob.GetBytes();
            var str = Encoding.Default.GetString(bytes);
            var test = JsonSerializer.Deserialize<Test>(str);
            Console.WriteLine($"{test.Id} {test.Name}");
        }

        var newId = max + 1;
        var t1 = new Test { Id = newId, Name = "Name_" + newId.ToString() };
        var t1json = JsonSerializer.Serialize(t1);
        var t1bytes = Encoding.Default.GetBytes(t1json);
        var t1b = new PersistentBlob(t1bytes);
        dic.Add(newId, t1b); 

@speed2048
Copy link

Thank you for the example are you running this under .netframework netstandard2.0 or netcoreapp3.1? I am still getting the issue with your example..

@ttustonic
Copy link
Author

It works in core 3.1 and .net 4.7.2 console apps.
Using nuget package Microsoft.Database.Collections.Generic ver 2.0.1
dic should be disposed at the end.

@speed2048
Copy link

That did it thank you... I had used my own compiled versions....

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