我在我的应用程序中使用AvalonDock,并注意到当我定位x64时,加载布局时似乎执行得慢得多。当我以x86为目标时,布局立即加载,但在64位时,它会在看到结果之前冻结大约一秒左右。
问题似乎与XmlSerializer在64位运行时性能更差有关,并且在谷歌搜索时,人们建议在编译时使用sgen.exe生成* .XmlSerializers.dll。不幸的是,这似乎不像运行sgen post build事件那样有效:
“$(SDK40ToolsPath)\x64\sgen.exe” /a:"$(TargetPath)" /force /r "Xceed.Wpf.AvalonDock.dll"
产生以下错误:
1>EXEC : error : Cannot deserialize type 'Microsoft.Windows.Shell.SystemParameters2' because it contains property 'IsGlassEnabled' which has no public setter.
我真的不想使用/ t命令来定位每种类型。
是否有其他人遇到过这个问题并有解决方案?
答案 0 :(得分:0)
我也遇到了这个问题,我发现的唯一解决方案是单独指定类型。我发现this article by Mikhail Shilkov显示了一种简洁的方法,可以为.csproj文件中的后期构建任务指定多种类型。我只指定了new XmlSerializer()
构造函数调用中引用的类型:
<Target Name="AfterBuild" DependsOnTargets="AssignTargetPaths;Compile;ResolveKeySource" Inputs="$(MSBuildAllProjects);@(IntermediateAssembly)" Outputs="$(OutputPath)$(_SGenDllName)">
<!-- This contents of this list was determined by looking at the new XmlSerializer() calls in the code. -->
<ItemGroup>
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutRoot" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutAnchorablePaneGroup" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutAnchorablePane" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutAnchorable" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutDocumentPaneGroup" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutDocumentPane" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutDocument" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutAnchorGroup" />
<SgenTypes Include="Xceed.Wpf.AvalonDock.Layout.LayoutPanel" />
</ItemGroup>
<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="$(SGenToolPath)" Types="@(SgenTypes)">
<Output TaskParameter="SerializationAssembly" ItemName="SerializationAssembly" />
</SGen>
</Target>
进行这些更改后,我遇到了另一个错误:
生成的序列化程序集未签名
通过从AssemblyInfo.cs中删除以下行来禁用签名解决了这个问题:
#pragma warning disable 1699
[assembly: AssemblyDelaySign( false )]
[assembly: AssemblyKeyFile( @"..\..\sn.snk" )]
[assembly: AssemblyKeyName( "" )]
#pragma warning restore 1699
另一种解决方案可能是启用Project Properties > Signing
登录,但我还没试过。