File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
src/runtime/StateSerialization Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 55namespace Python . Runtime ;
66
77public class NoopFormatter : IFormatter {
8- public object Deserialize ( Stream s ) => throw new NotImplementedException ( ) ;
8+
9+ public object Deserialize ( Stream s ) => throw new NotImplementedException (
10+ "Cannot deserialize using 'NoopFormatter', implement 'Python.Runtime.RuntimeData.FormatterType' if needed"
11+ ) ;
12+
913 public void Serialize ( Stream s , object o ) { }
1014
1115 public SerializationBinder ? Binder { get ; set ; }
Original file line number Diff line number Diff line change @@ -15,18 +15,43 @@ namespace Python.Runtime
1515{
1616 public static class RuntimeData
1717 {
18+ //TODO: put it in a utility class instead of inside the RuntimeData Class.
19+ private static Version ? GetNetVersion ( string verToCheck )
20+ {
21+ // Examples:
22+ // ".NET 8.0.0"
23+ // ".NET 9.0.0"
24+ // ".NET Framework 4.8.1"
25+ // ".NET Core 3.1.32"
26+ string desc = RuntimeInformation . FrameworkDescription ;
27+ if ( desc . StartsWith ( verToCheck , StringComparison . OrdinalIgnoreCase ) )
28+ {
29+ var verStr = desc . Split ( ' ' ) . Last ( ) ;
30+ if ( Version . TryParse ( verStr , out var ver ) )
31+ return ver ;
32+ }
33+ return null ;
34+ }
1835
1936 public readonly static Func < IFormatter > DefaultFormatterFactory = ( ) =>
2037 {
21- try
38+ //The issue here is that just instancing BynaryFormatter doesn't solve the problem.
39+ //you need to use it to generate the exception.
40+ /*try
2241 {
2342 return new BinaryFormatter();
2443 }
2544 catch
2645 {
2746 return new NoopFormatter();
47+ }*/
48+ var ver = GetNetVersion ( ".NET" ) ;
49+ if ( ver != null && ver . Major >= 9 ) {
50+ return new NoopFormatter ( ) ;
51+ } else {
52+ return new BinaryFormatter ( ) ;
2853 }
29- } ;
54+ }
3055
3156 private static Func < IFormatter > _formatterFactory { get ; set ; } = DefaultFormatterFactory ;
3257
You can’t perform that action at this time.
0 commit comments