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

PlatformNotSupportedException when serializing some ISerializable types on dotnet core 2.0 #1404

Closed
Cisien opened this issue Aug 19, 2017 · 5 comments

Comments

@Cisien
Copy link

Cisien commented Aug 19, 2017

Source/destination types

System.IO.DirectoryInfo

Source/destination JSON

None/serialization fails.

Expected behavior

Serialization of the DirectoryInfo object to function how it works on .net 4.x

Actual behavior

Message: System.PlatformNotSupportedException : Operation is not supported on this platform.
at System.IO.FileSystemInfo.GetObjectData(SerializationInfo info, StreamingContext context)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at CSDiscordService.EvalTests.<JsonConvertOfDirectoryInfoObject>d__15.MoveNext() in C:\src\CSDiscord\CSDiscordService.Tests\EvalTests.cs:line 88
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Result Message:	System.PlatformNotSupportedException : Operation is not supported on this platform.

Appears to be related to a change made in the .net core implementation to no longer support serializing several types.
dotnet/corefx#20220

Steps to reproduce

PM> dotnet --info
.NET Command Line Tools (2.0.1-servicing-006924)

Product Information:
 Version:            2.0.1-servicing-006924
 Commit SHA-1 hash:  1ed6be56ca

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.16257
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.1-servicing-006924\

Microsoft .NET Core Shared Framework Host
  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
var di = Directory.CreateDirectory("C:\\this\\doesnt\\exist");
var json = JsonConvert.SerializeObject(di);
Console.WriteLine(json);

Other Observations

SerializerSettings.Error = (s, e) => e.ErrorContext.Handled = true; does not handle this exception
setting SerializerSettings.ContractResolver = new DefaultContractResolver { IgnoreSerializableInterface = true }; does not change this behavior

@JamesNK
Copy link
Owner

JamesNK commented Dec 5, 2017

Fixed a couple of months ago. Test 9051418

@JamesNK JamesNK closed this as completed Dec 5, 2017
@Cisien
Copy link
Author

Cisien commented Dec 5, 2017

That test doesnt seem to have anything to do with this issue?

@JamesNK
Copy link
Owner

JamesNK commented Dec 5, 2017

It shows that the type isn't being serialized using ISerializable

@CarlosOnline
Copy link

Any status on this issue? I am also seeing the same problem with dotnet version 2.1.2

@Cisien
Copy link
Author

Cisien commented Jan 3, 2018

Grab the latest pre-release of Newtonsoft.Json

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

3 participants