【问题标题】:Directory does not exist - Parameter name: directoryVirtualPath目录不存在 - 参数名称:directoryVirtualPath
【发布时间】:2012-07-04 17:08:38
【问题描述】:

我正在使用 Visual Studio Express 2012 RC。

  • 如果创建一个空白的“hello world MVC 4.5 项目”
  • 我将其降级为 4.0,以便与我的主机 (Arvixe) 兼容
  • 我将它发布给主机。

然后我收到此错误消息,我可以在网上找到有关它的任何信息。

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

什么意思?

按要求编码^^

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return Content("Hello world");
    }
}

这是我添加的唯一代码。

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);
    }
}

路由配置

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 }
        );
    }
}

过滤器配置

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"));
    }
}

【问题讨论】:

  • 当然可以,但这只是一个测试。
  • 你能把代码贴在 application_start 里面吗?
  • @BjarkeCK 谢谢。您确定 RegisterBundles 中包含的所有文件都存在于您的应用程序目录中吗?
  • @BehnamEsmaili 有趣,我发布时可能排除了 Content 文件夹:),将尝试删除所有捆绑包并再次发布!

标签: c# asp.net-mvc iis stack-trace visual-studio-2012


【解决方案1】:

似乎此错误源于“未在您的应用程序目录中包含所需文件”或将您的代码上传到未配置为虚拟目录的目录中, 甚至在错误的目录中。

【讨论】:

  • 我觉得你说的很对 :) 会测试一下,一会儿就回来
  • 嗯,我认为解决了这个问题,但现在它是一个新问题:http:**temp.iconbench.com/
  • 检查这是否有帮助? stackoverflow.com/questions/3297048/…
  • 好吧,现在我至少更近了一步。非常感谢您的帮助,学到了很多。
【解决方案2】:

此帖类似于Directory does not exist. Parameter name: directoryVirtualPath

答案帮助我调试。显然,目标服务器上缺少文件夹。我的应用程序在本地运行良好,但是当我发布时,几个script 子目录没有发布。当我手动 FTP 上传它们时,该应用程序运行良好!

【讨论】:

  • 这也是我的问题。默认情况下,Visual Studio 似乎不会发布空目录,即使应用程序使用它们并且它们包含在项目中。
【解决方案3】:

在这里扩展信息。

我经常将所有文件捆绑在一个文件夹中,如下所示:"~/Content/js/angular/modules/*.js", 只要文件夹存在,它就可以很好地工作。

问题是,如果您发布时该文件夹为空,它将不会被发布,并会导致上述异常。所以现在我要么放一个empty.txt,要么手动添加文件夹,如果我想让它们暂时保持空白。

【讨论】:

  • 啊,这节省了我几个小时 :) 谢谢
【解决方案4】:

检查 bin 文件夹中是否有 dll,并且该 dll 是否存在于 GAC 中

从 GAC 中移除 dll

【讨论】:

    【解决方案5】:

    在我的情况下,它是我忘记上传到服务器的“内容”文件夹

    【讨论】:

      【解决方案6】:

      创建目录“/Content/themes/base”

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-05-27
        • 1970-01-01
        • 2012-10-26
        • 2022-01-13
        • 2019-12-10
        • 1970-01-01
        相关资源
        最近更新 更多