Does SGen generate xml serialization assemblies only if all setters are public?
I've got this class in DummyProject:
public class DummyClass
{
public int Sequence { get; internal set; }
}
In my AssemblyInfo.cs, I've declared this:
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DummyProject.XmlSerializers")]
In my csproj, I've put this:
<Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
<SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(SGenToolPath)">
<Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
</SGen>
Current error is:
Cannot deserialize type 'DummyProject.DummyClass' because it contains property 'Sequence' which has no public setter.
What I have tried: 1. Now, if I take out the internal setter, I have no problems generating the DummyProject.XmlSerializer.
Am I missing something?
My assemblyinfo.cs does not contain this as listed in 1 of the pitfalls:
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
- I also have tried signing my assemblies and modifying the InternalsVisibleTo to include the public key but I still get the same error.
Is it a problem with the InternalsVisibleTo?
Base on this post, SGen should still be able to generate the xml serialization assembly even with the internal setter.
SGEN, InternalsVisibleTo and assembly signing
- I didn't use the post build steps to generate the xml serialization assembly. I did it in Developer Command Prompt and the assembly is created successfully for classes with no internal setters. Now, I copied this assembly to my project output & change my property setter to internal. I've got an error during serialization because of the internal setter.
Of course, I've added the InternalsVisibleTo in my AssemblyInfo.cs..
I think Joe may have found the solution:
REFERENCE
SGEN, InternalsVisibleTo and assembly signing