1

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("")]
  1. 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

  1. 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..
Community
  • 1
  • 1
simplySane
  • 11
  • 1
  • Tried this in VS2008 and it works. SGen in VS2008 works fine even if internal setters existed. Bug in VS2012? – simplySane Aug 01 '13 at 07:49
  • For reference: *Visual Studio 2013*'s `sgen` is also generating errors for classes marked as `internal` – Pressacco May 09 '14 at 13:46

1 Answers1

0

I think Joe may have found the solution:

"In the InternalsVisibleTo attribute, you need to specify the full public key, not just the public key token.

See this answer to a similar question and this MSDN article for info on how to get the public key."

REFERENCE

SGEN, InternalsVisibleTo and assembly signing

Community
  • 1
  • 1
Pressacco
  • 2,815
  • 2
  • 26
  • 45