I am creating a AppDomain using the below code
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);
But _Domain.DynamicDirectory property does not exist. https://msdn.microsoft.com/en-us/library/system.appdomain.dynamicdirectory(v=vs.110).aspx clearly says the AppDomainSetup.DynamicBase is used.
What could be the reason executing in vstest.console.exe changes the behavior with App Domains. Is there a work around.
Solution
Check if the
AppDomain.CurrentDomain.FriendlyNamecontains illegal characters such as a colon (:). If yes you should sanitizesetup.ApplicationNamewith one of the methods discussed in the SO question How to remove illegal characters from path and filenames?.Background
When I debugged the test I got a
System.NotSupportedExceptionwith the messageThe given path's format is not supported..The stack trace was
And the value of
AppDomain.CurrentDomain.FriendlyNamewasTestSourceHost: Enumering assembly.A quick look at the reference source of
EmulateFileIOPermissionChecks- which is the last method that appears in the stack trace - revealed that it throws aNotSupportedExceptionifPathInternal.HasInvalidVolumeSeparatorreturns true. That method contains the following comment:The string
TestSourceHost: Enumering assemblyclearly violates that rule.