Serialization Exception when openning Dictionary<> from different framework
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 574
- Forks
- 104
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
When I try to open a PsiStore collected in a different framework (.NET Core) in a .NET framework program a serialization error is thrown:
System.Runtime.Serialization.SerializationException
HResult=0x8013150C
Message=The schema System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e version 2 (implemented by System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) is missing the following members required in the current version of System.Collections.Generic.Dictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089: buckets,entries,count,version,freeList,freeCount,comparer,keys,values,_syncRoot
Source=Microsoft.Psi
StackTrace:
at Microsoft.Psi.Serialization.TypeSchema.ValidateCompatibleWith(TypeSchema other)
at Microsoft.Psi.Serialization.TypeSchema.GetCompatibleMemberSet(TypeSchema targetSchema)
at Microsoft.Psi.Serialization.ClassSerializer`1.Initialize(KnownSerializers serializers, TypeSchema targetSchema)
at Microsoft.Psi.Serialization.KnownSerializers.AddHandler[T]()
at Microsoft.Psi.Serialization.KnownSerializers.GetHandler[T]()
at Microsoft.Psi.Components.DeserializerComponent`1..ctor(Pipeline pipeline, KnownSerializers serializers, T reusableInstance)
at Microsoft.Psi.Data.Importer.OpenStream[T](String streamName, T reusableInstance)
at psi_dict_test.Program.Read() in D:\psi-dict-test\Program.cs:line 26
at psi_dict_test.Program.Main(String[] args) in D:\psi-dict-test\Program.cs:line 35
I also find the reverse to be true too, but interestingly no error is thrown in PsiStudio.
Here is the code that generates the PsiStores:
namespace psi_dict_test
{
using System;
using System.Collections.Generic;
using Microsoft.Psi;
class Program
{
static void Write()
{
using (var p = Pipeline.Create())
{
var gen = Generators.Repeat(p, new Dictionary<string, int>() { { "hello", 1} }, 1, TimeSpan.Zero);
var store = Store.Create(p, "write-w-core", "store");
gen.Write("dict", store);
p.Run();
}
}
static void Read()
{
using (var p = Pipeline.Create())
{
var store = Store.Open(p, "write-w-core", "store");
store.OpenStream<Dictionary<string, int>>("dict").Do(m =>{
Console.WriteLine(m["hello"]);
});
p.Run();
}
}
static void Main(string[] args)
{
Read();
}
}
}
Here are the two generated PsiStores:
write-w-core.0000.zip
write-w-framework.0000.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with TypeSchema.ValidateCompatibleWith and GetCompatibleMemberSet in the stack trace, then follow ClassSerializer.Initialize through Importer.OpenStream. Reproduce the failure using the attached PsiStores and the sample Program.Read code. Done means stores written under .NET Core and .NET Framework can both be opened without a serialization exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100