Implemements a System.Xml.Serialization based NServiceBus message serializer to allow better interoperability with non-NServiceBus peers.
In the Init
method of an IWantToRunBeforeConfiguration
, call Configure.Serialization.SystemXml(s=>s.SkipWrappingSingleMessage());
.
The System.Xml.Serialization is currently known to trigger undesirable behavior in the 64 bit .NET JIT optimizer (Microsoft Connect issue about the issue).
The memory consuption issue seems to be resolved with the next major release of the .NET JIT RyuJIT. It can also be avoided by using the current 32-Bit VM (e.g. by using the 32-bit NServiceBus host executable).
If there is memory trouble with serializing messages using this serializer and the 64 bit VM has to be used, do the following.
- Create sgened assembly for the contracts assembly by adding the following to the msbuild for the contract. In order for sgen to work properly, it's adviced that an assembly be created per contract.
<Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
<Delete Files="$(TargetDir)$(TargetName).XmlSerializers.dll" ContinueOnError="true" />
<SGen BuildAssemblyName="$(TargetFileName)" BuildAssemblyPath="$(OutputPath)" References="@(ReferencePath)" ShouldGenerateSerializer="true" UseProxyTypes="false" KeyContainer="$(KeyContainerName)" KeyFile="$(KeyOriginatorFile)" DelaySign="$(DelaySign)" ToolPath="$(TargetFrameworkSDKToolsDirectory)" Platform="$(Platform)">
<Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
</SGen>
</Target>
- Disable the JIT optimizer on the generated assembly by creating a .NET debugging control config file for the XMLSerializer assembly created above. For example
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0