C# 目录不存在 - 参数名称:directoryVirtualPath
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11333137/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Directory does not exist - Parameter name: directoryVirtualPath
提问by BjarkeCK
I am using Visual Studio Express 2012 RC.
我正在使用 Visual Studio Express 2012 RC。
- If a create a blank "hello world MVC 4.5 project"
- I Downgrade it to 4.0 so it is compatible with my host (Arvixe)
- I publish it to the host.
- 如果创建一个空白的“hello world MVC 4.5 项目”
- 我将其降级到 4.0,因此它与我的主机 (Arvixe) 兼容
- 我将其发布给主机。
And then i get this error message, i can find any information on it online.
然后我收到此错误消息,我可以在网上找到有关它的任何信息。
Server Error in '/' Application.
Directory does not exist.
Parameter name: directoryVirtualPath
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.Optimization.Bundle.IncludeDirectory(String directoryVirtualPath, String searchPattern, Boolean searchSubdirectories) +357
System.Web.Optimization.Bundle.Include(String[] virtualPaths) +287
IconBench.BundleConfig.RegisterBundles(BundleCollection bundles) +75
IconBench.MvcApplication.Application_Start() +128
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9160125
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +131
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +194
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +339
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +253
[HttpException (0x80004005): Directory does not exist.
Parameter name: directoryVirtualPath]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9079228
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +97
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +256
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237
What does it mean ?
这是什么意思 ?
Code as requested^^
代码按要求^^
public class HomeController : Controller
{
public ActionResult Index()
{
return Content("Hello world");
}
}
thats the only code i added.
那是我添加的唯一代码。
application_start code
application_start 代码
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
RouteConfig
路由配置
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
FilterConfig
过滤器配置
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
}
BundleConfig
捆绑配置
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
}
采纳答案by Behnam Esmaili
it seems that this error originates from "not including desired files in your application's directory" or uploading your code in a directory that is not configured as virtual directory , or even in incorrect directory.
此错误似乎源于“未在您的应用程序目录中包含所需文件”或将您的代码上传到未配置为虚拟目录的目录中,甚至在不正确的目录中。
回答by WSG
This post is similar to Directory does not exist. Parameter name: directoryVirtualPath
这篇文章类似于目录不存在。参数名称:directoryVirtualPath
The answer helped me debug. Apparently, there are missing folders on the target server. My application worked fine locally, but when I published, several scriptsub-directories did not get published. When I manually FTP'd them up, the app worked fine!
答案帮助我调试。显然,目标服务器上缺少文件夹。我的应用程序在本地运行良好,但是当我发布时,几个script子目录没有发布。当我手动通过 FTP 将它们连接起来时,该应用程序运行良好!
回答by Matthew.Lothian
To expand on the information here.
在这里扩展信息。
I often bundle all file in a folder like so: "~/Content/js/angular/modules/*.js",And this works great as long as the folder exists.
我经常像这样将所有文件捆绑在一个文件夹中:"~/Content/js/angular/modules/*.js",只要文件夹存在,这就会很好地工作。
The issue is, if that folder is empty when you publish it will not be published and will result in the above exception. So now i either put an empty.txt or something of the sort of add the folder manually if i want them to remain empty for now.
问题是,如果该文件夹在您发布时为空,它将不会被发布,并会导致上述异常。所以现在我要么放一个 empty.txt 要么手动添加文件夹,如果我想让它们暂时保持为空。
回答by aspmvcnet.com
Create directory "/Content/themes/base"
创建目录“/Content/themes/base”
回答by WantToDo
check if you have dll in bin folder and also the dll exist in the GAC
检查 bin 文件夹中是否有 dll 以及 GAC 中是否存在该 dll
remove dll from GAC
从 GAC 中删除 dll
回答by geekonweb
In my case it was "Content" folder which I forgot to upload to the server
就我而言,它是我忘记上传到服务器的“内容”文件夹

