-
-
Notifications
You must be signed in to change notification settings - Fork 456
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
Deserialize object serialized with older assembly version #134
Comments
Hi @MichalJakubeczy yes, I have to store the actual type of the object stored in Redis for example, because, otherwise, the de/serialization will be very difficult, especially if the generic type of CacheManager doesn't match the type stored. I just did some testing around this and found that unsigned assemblies actually work just fine. For now, you can try to use unsigned assemblies to work around that issue. I will have to implement custom type resolvers and maybe even expose an interface or something so that you could inject your custom type resolver to work around those things... Hope that helps! Sorry that I cannot give you a better fix right away. |
Thanks @MichaCo for your effort. Unfortunately we cannot use unsigned assemblies right away. One more workaround came to my mind - adding assembly version to the cache key would separate old values from the new ones. Old ones will disapear as they don't get accessed (key with old assembly version will not get accessed) and new ones will be added. It will cause some performance drop right after the release of new version (we can't use cached stuff), but better than nothing. |
… attach them into the serialization process. Also, made the default type resolver more robust and added some fallbacks. No, it also tries to resolve the type without a version...
@MichalJakubeczy I just added a few adjustments to the way I'm loading the types. If something still doesn't work for you, there is a new method to add custom type resolvers.
The method is allowed to return null or throw an exception without breaking the logic. It would be great if you could try to consume the latest beta package from the myget feed (0.9.4-beta-1446 has the latest bits) and test that with your case and let me know if the standard resolver (without custom resolver) now works. Thanks! |
@MichaCo - wow, thanks for a quick response. I will give it a try in upcoming days and let you know about the result. Is week fast enough? |
@MichalJakubeczy sure np ;) |
@MichaCo - I tested it and it seems to be working :) Could you please make a release via nuget, so we can start using it in our solution. Thanks. |
@MichalJakubeczy I decided to release a beta of all packages to Nuget. You can consume those and see how it goes. I will need a little bit more time/testing to wrap that 1.0.0 release up. Mostly because of the move to VS2017 project system. |
@MichaCo OK, thanks for letting me know. I will carry on using beta in mine local environment and let you know about any issues. But we can't use beta stuff in Production environment for obvious reasons :) Will 1.0.0 contain this fix as well (if nothing unexpected happens)? |
yeah 1.0.0 does have all the fixes/changes. Unfortunately there are some issues with the packages. Dependencies don't get resolved correctly. Ok if you cannot use beta stuff anyways then you have to wait a little bit ;) Hopefully before/through the weekend I'll have time to get this release done |
Where do we specify this in a DI environment ? CacheManager.Core.Internal.TypeCache.RegisterResolveType((name) => |
Why do you think you have to use this function? It should be just a "workaround" if the build in TypeLoader doesn't work in some serialization scenarios. So, if you have a particular issue with something, would be interesting to know. |
I am using cachemanager in web api project and .net core with json serializer. I do not want to store type in redis. Shouldn't json should be type agnostic ? |
I have defined: CacheManager.Core.Internal.TypeCache.RegisterResolveType((name) => But the type is still showing up redis. |
@zorrme I think you misunderstand the purpose of the TypeCache. CacheManager needs to store the type's name of the actual cached value separated to the value, so that when it read the data the next time, it can deserialize it into the correct type. The generic In short, what you are trying to do is not supported. |
@MichaCo Thanks for the suggestion, but unfortunately string is also stored as a type. Can we have a version of cache manager which does not store types ? |
@zorrme Just curious, but what is the problem with storing the type name as one of the meta data in Redis? I honestly don't get it.
No.
I explained that in the last answer, there is no way to guess the type when reading a json object. |
@MichaCo I am using two apps to store same POCO in redis. If we write to redis from app1, app2 cannot read it because of type mismatch and vice-versa. |
@zorrme It it would really be the same POCO, it would probably work (shared library even with different versions now). Just guessing here, but, you are defining the POCO twice, in each APP? Meaning the type is actually totally different? Solutions: If you still have issues, please use StackOverflow with example code to reproduce it. |
We are serializing objects of assembly with version e.g. 1.0.125.10594, these are also stored to Redis cache. Then we deploy a new release (with new version of DLLs, e.g. 1.0.126.11000) and we observe FileLoadException.
Stacktrace:
There seems to be a problem that during deserialization of value from cache old assembly is not found (obviously) and object can not be deserialized and retrieved.
We configure CacheManager like this:
so according to documentation JSON should be version agnostic.
Where might the problem lay?
The text was updated successfully, but these errors were encountered: