Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Using FormattingUtilities.XsdDataContractExporter.GetRootElementName(type) throws in netcoreapp2.0 when used in ExplicitResponseTypeDecoration_WithExplicitDefaultStatus_SpecifiedViaProducesAttribute #6235

Closed
pranavkm opened this issue May 4, 2017 · 4 comments
Assignees
Milestone

Comments

@pranavkm
Copy link
Contributor

pranavkm commented May 4, 2017

Type 'Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.

   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.ThrowInvalidDataContractException(String message, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.CreateDataContract(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContract.DataContractCriticalHelper.GetDataContractSkipValidation(Int32 id, RuntimeTypeHandle typeHandle, Type type)
   at System.Runtime.Serialization.DataContract.GetDataContract(RuntimeTypeHandle typeHandle, Type type, SerializationMode mode)
   at System.Runtime.Serialization.XsdDataContractExporter.GetRootElementName(Type type)
   at Microsoft.AspNetCore.Mvc.Formatters.XmlDataContractSerializerOutputFormatter.CreateSerializer(Type type)
@pranavkm
Copy link
Contributor Author

pranavkm commented May 4, 2017

Here's the code to be inserted in XmlDataContractSerializerOutputFormatter.CreateSerializer:

// Verify that type is a valid data contract by forcing the serializer to try to create a data contract
FormattingUtilities.XsdDataContractExporter.GetRootElementName(type);

@rynowak
Copy link
Member

rynowak commented May 4, 2017

We're not supposed to directly serialize MSD, that's what the serialization proxies are for.

@pranavkm
Copy link
Contributor Author

pranavkm commented May 4, 2017

Something in the code path is attempting to serialize it and it throws (which apparently worked on desktop?). Filed a bug so we can move on with the TFM conversion for the time being because we previously weren't calling this API from netcoreapp

@pranavkm
Copy link
Contributor Author

pranavkm commented Jul 6, 2017

Self-assigning to see if we missed something doing the TFM conversions.

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

No branches or pull requests

2 participants