Testing: The application relative virtual path ‘~/’ is not allowed here.
If you’re running unit tests in an ASP.NET web app on code accessing settings from the web.config, then you might have some code like:
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
That will work fine when you run the project, but your test will fail and give you the error ‘The application relative virtual path ‘~/’ is not allowed here.’. Fortunately, there is the HttpRuntime.AppDomainAppVirtualPath property you can use for the path, which works in tests as well as when running. (In tests this value is null.) So you code would then look like:
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpRuntime.AppDomainAppVirtualPath);
HttpRuntimeSection section = config.GetSection("system.web/httpRuntime") as HttpRuntimeSection;
And your test will work.
One Response to Testing: The application relative virtual path ‘~/’ is not allowed here.
-
Calendar
June 2013 M T W T F S S « Jul 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 -
Meta






you save my job man! thank you! =)