0

I currently have connected services in a c# project. These are C# files generated by importing wsdl files. I'd like to serialize some of the generated classes to xml, which requires generated classes to be public. But my project is meant to be deployed in a nuget package and I don't want the generated code to be accessible by an user of my package.

How can I do that ? Nuget seems to expose everything public. And XmlSerializer requires things to be public.

Thank you in advance for any idea.

Poc
  • 109
  • 10
  • Does this answer your question? [How can I serialize internal classes using XmlSerializer?](https://stackoverflow.com/questions/6156692/how-can-i-serialize-internal-classes-using-xmlserializer) – gunr2171 Jun 25 '21 at 12:12
  • @gunr2171 that's the first link I saw, it's a interesting solution I'd apply in some experimental project, but here it looks like a hack, with a command line build process that (I think) would make all the ci/cd more complicated. I'd prefer a solution which doesn't require to build the project twice :) I considered using reflection for changing internal to private dynamically, but couldn't achieve it, for example. – Poc Jun 25 '21 at 13:08
  • Does `DataContractSerializer` meet your needs? It can serialize internal types when marked with data contract attributes and when running in full trust. See [Types Supported by the Data Contract Serializer](https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/types-supported-by-the-data-contract-serializer). – dbc Jun 25 '21 at 23:44
  • @dbc I tried, seems it doesn't deserialize the objects that XmlSerializer deserializes (I just tried). I guess it's not compatible. – Poc Jun 28 '21 at 13:58

0 Answers0