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

Consider defaulting to another serializer than binary #91

Open
fredericDelaporte opened this issue Nov 11, 2020 · 13 comments
Open

Consider defaulting to another serializer than binary #91

fredericDelaporte opened this issue Nov 11, 2020 · 13 comments

Comments

@fredericDelaporte
Copy link
Member

Binary serialization (BinaryFormatter) is made obsolete in .Net 5.

Some caches use it by default. They have to be made obsolete themselves for .Net 5, or changed for another serialization default when possible.

(Issue extracted from nhibernate/nhibernate-core#2603.)

@gokhanabatay

This comment has been minimized.

@fredericDelaporte

This comment has been minimized.

@maca88

This comment has been minimized.

@danspam
Copy link

danspam commented Jul 11, 2021

Alternative serializers like Message Pack require you to annotate the properties of your objects to identify which properties to serialize. Which properties of your entities do you need to serialize at minimum for NHibernate cache to function correctly? Child collections / Many-to-one properties / etc?

@fredericDelaporte
Copy link
Member Author

fredericDelaporte commented Jul 16, 2021

This is implementation specific. Some caches do not need serialization at all. Those needing it usually require serializing the complete state.

This state is not the entities or collections themselves, but their "dehydrated" versions, which means, simple arrays of atomic types. Some caches also adds some of their own state in the serialized data though.

@ghost
Copy link

ghost commented Jan 10, 2022

Hi,
for .net6 there seems to be no workaround using the binary serializer and you have to switch (https://docs.microsoft.com/de-de/dotnet/standard/serialization/binaryformatter-security-guide)
I'm having trouble using the JsonCacheSerializer and IDistributedCache and cannot find much documentation or advice. Currently using MemoryDistributedCache and also want to use RedisCache.
It fails for me for simple types like Tuple<object, object>, CacheKey, QueryKey - and I'm not even sure I should register these types as they are NHibernates internals? Even if I do it fails later when deserializing CacheKey - do I need to add my own contracts for NH types?
Is there any further sample code or documentation to check out other than the docs stating "use JsonCacheSerializer" and the tests in this project?
Thanks

@danspam
Copy link

danspam commented Jan 10, 2022

We ended up using the JsonCacheSerializer with StackExchangeRedisCache when moving away from binary serializer. It seemed the only reasonable option. Our configuration is :

cfg.AddProperties(new Dictionary<string, string> {
    {
        RedisEnvironment.Serializer,
        typeof(global::NHibernate.Caches.Util.JsonSerializer.JsonCacheSerializer).AssemblyQualifiedName
    }
});

Only other thing that needed to be done is to ensure the Assemble and Disassemble methods for custom types are correctly implemented.

@spasecookee

This comment was marked as outdated.

@fredericDelaporte
Copy link
Member Author

No need, see #117. But 5.9 is not yet released.

@odavidbrito

This comment was marked as outdated.

@fredericDelaporte

This comment was marked as outdated.

@fredericDelaporte
Copy link
Member Author

5.9.0 is now released.

@spasecookee
Copy link

Works beautifully without having to use my own ConfigureJsonCacheSerializer() code. Many thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants