我正在使用下面的代码创建一个AppDomain
String pa = @"C:\Users\user\AppData\Local\Temp\2\db5fjamk.xnl";
System.IO.Directory.CreateDirectory(pa);
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; //f:\projectpath\out\debug-i386-unittest\UnitTests
setup.ApplicationName = string.Concat(AppDomain.CurrentDomain.FriendlyName, DateTime.UtcNow.Ticks); //UnitTestAdapter: Running test636559691791186101
setup.DynamicBase = pa;
Evidence evidence = AppDomain.CurrentDomain.Evidence;
_Domain = AppDomain.CreateDomain(setup.ApplicationName, evidence, setup);但是_Domain.DynamicDirectory属性不存在。https://msdn.microsoft.com/en-us/library/system.appdomain.dynamicdirectory(v=vs.110).aspx明确表示使用了AppDomainSetup.DynamicBase。
在vstest.console.exe中执行的原因是什么改变了应用程序域的行为。这附近有工作吗。
发布于 2018-03-10 06:33:40
溶液
检查AppDomain.CurrentDomain.FriendlyName是否包含非法字符,如冒号(:)。如果是,您应该使用SO问题setup.ApplicationName中讨论的方法之一对How to remove illegal characters from path and filenames?进行消毒。
背景
当我调试测试时,我得到了一个带有消息System.NotSupportedException的The given path's format is not supported.。
堆栈跟踪是
at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath)
at System.Security.Permissions.FileIOPermission.QuickDemand(FileIOPermissionAccess access, String fullPath, Boolean checkForDuplicates, Boolean needFullPath)
at System.AppDomain.get_DynamicDirectory()
at System.AppDomain.get_DynamicDirectory()
at SO_AppDomain.Sut.Method() in <path>\Program.cs:line 30
at UnitTestProject1.UnitTest1.TestMethod1() in <path>\UnitTest1.cs:line 14AppDomain.CurrentDomain.FriendlyName值为TestSourceHost: Enumering assembly。
快速查看EmulateFileIOPermissionChecks (这是堆栈跟踪中出现的最后一个方法)就会发现,如果PathInternal.HasInvalidVolumeSeparator返回true,它将抛出一个NotSupportedException。该方法包含以下注释:
// Toss out paths with colons that aren't a valid drive specifier.
// Cannot start with a colon and can only be of the form "C:" or "\\?\C:".字符串TestSourceHost: Enumering assembly显然违反了该规则。
https://stackoverflow.com/questions/49160044
复制相似问题