我正在尝试使用.runsettings
文件执行测试,但测试运行失败并显示以下消息:
------ Run test started ------
Some or all identity references could not be translated.
Operation is not valid due to the current state of the object.
========== Run test finished: 0 run (0:00:00,2280287) ==========
EventLog提供了有关错误的更多详细信息:
Error Handler Exception: System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.NTAccount.Translate(Type targetType)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IISResetter.CreateSidFromUser(String userName)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.GetUserFromAppPool(ApplicationPool pool)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.get_Users()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.get_AllowedUsers()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Microsoft.VisualStudio.TestTools.Execution.ITestExecutionEnvironmentSpecifier.GetTestExecutionEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.TestPlatformDataCollectorInfo.GetTestExecutionEnvironmentVariablesSync()
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadAndInitDataCollectors(DataCollectionRunSettings dataCollectionSettings, Boolean& allCollectorsLoaded)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadDataCollectors(RunSettings testRunSettings, Boolean& allCollectorsLoaded)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.WcfTestRunnerService.BeforeTestRunStart(String settingsXml, Boolean resetDataCollectors, Boolean isRunStartingNow)
at SyncInvokeBeforeTestRunStart(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) \r\n at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.NTAccount.Translate(Type targetType)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IISResetter.CreateSidFromUser(String userName)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.GetUserFromAppPool(ApplicationPool pool)
at Microsoft.VisualStudio.Enterprise.WebInstrument.IIS7Resetter.get_Users()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.get_AllowedUsers()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.InitiateCollection()
at Microsoft.VisualStudio.TraceCollector.CommonDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.GetEnvironmentVariables()
at Microsoft.VisualStudio.TraceCollector.BaseDataCollector.Microsoft.VisualStudio.TestTools.Execution.ITestExecutionEnvironmentSpecifier.GetTestExecutionEnvironmentVariables()
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.TestPlatformDataCollectorInfo.GetTestExecutionEnvironmentVariablesSync()
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.GetEnvironmentVariables(Boolean& unloadedAnyCollector)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadAndInitDataCollectors(DataCollectionRunSettings dataCollectionSettings, Boolean& allCollectorsLoaded)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.DataCollectors.DataCollectionPluginManager.LoadDataCollectors(RunSettings testRunSettings, Boolean& allCollectorsLoaded)
at Microsoft.VisualStudio.TestPlatform.TestRunnerService.WcfTestRunnerService.BeforeTestRunStart(String settingsXml, Boolean resetDataCollectors, Boolean isRunStartingNow)
at SyncInvokeBeforeTestRunStart(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
删除.runsettings
文件可以解决问题,但我们要在coverage报告中包含一些要排除的程序集。
答案 0 :(得分:1)
事实证明,当您包含此类文件时,ASP.NET代码覆盖率集合将激活。这又需要重置应用程序池以将其自身附加到它。 (因此引用IIS7Resetter
)。关闭ASP.NET代码Coverage收集功能可以解决错误:
<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<!-- Include the below line in your .runsettings file-->
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
但这并没有解释出现了什么问题。由于Stack Trace提示App Pool用户,我们开始调查。事实证明,将应用池设置为LocalSystem
或NetworkService
实际上也可以解决问题。我们将其配置为.\SomeLocalUser
。更多的修补工作找到了根本原因,用于获取应用程序池标识的代码不喜欢简短的符号。实际输入机器名称会完全修复它:MachineName\SomeLocaluser
。我怀疑这是Visual Studio中的一个实际错误,它将在未来的时间框架内修复,但在此之前这两个选项可能会帮助其他人找出问题所在。
注意:默认情况下,默认情况下最好将CollectAspDotNet
选项设置为False
。只要您没有针对服务器运行集成测试或CodedUI测试,它就会大大加快您的测试运行速度。
另见: