디렉토리가 없습니다. 매개 변수 이름 : directoryVirtualPath 및 답변이 올바른 이유에 대한

방금 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

무슨 뜻인가요 ?



답변

나는 같은 문제가 있었고 {version} 및 *와 같은 와일드 카드를 사용하여 존재하지 않는 파일을 가리키는 일부 번들이 있음을 알았습니다.

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    "~/Scripts/jquery-{version}.js"));

나는 그것들을 모두 제거하고 오류가 사라졌습니다.


답변

나는 똑같은 문제가 있었고 코드 문제가 아닙니다. 게시 옵션 (FTP 아님)을 사용하고 있었고 Visual Studio는 일부 스크립트 / css가 “내 프로젝트에 포함”되지 않았기 때문에 azure 서버에 업로드하지 않았습니다. 그래서 로컬에서는 파일이 내 하드 드라이브에 있었기 때문에 잘 작동했습니다. 제 경우에이 문제를 해결 한 것은 “프로젝트> 모든 파일 표시 …”였습니다. 포함되지 않은 파일을 마우스 오른쪽 버튼으로 클릭하고 포함하고 다시 게시합니다.


답변

이 작업을 쉽게하기 위해 작성한 간단한 수업이 있습니다.

using System.Web.Hosting;
using System.Web.Optimization;

// a more fault-tolerant bundle that doesn't blow up if the file isn't there
public class BundleRelaxed : Bundle
{
    public BundleRelaxed(string virtualPath)
        : base(virtualPath)
    {
    }

    public new BundleRelaxed IncludeDirectory(string directoryVirtualPath, string searchPattern, bool searchSubdirectories)
    {
        var truePath = HostingEnvironment.MapPath(directoryVirtualPath);
        if (truePath == null) return this;

        var dir = new System.IO.DirectoryInfo(truePath);
        if (!dir.Exists || dir.GetFiles(searchPattern).Length < 1) return this;

        base.IncludeDirectory(directoryVirtualPath, searchPattern);
        return this;
    }

    public new BundleRelaxed IncludeDirectory(string directoryVirtualPath, string searchPattern)
    {
        return IncludeDirectory(directoryVirtualPath, searchPattern, false);
    }
}

이를 사용하려면 다음과 같이 코드에서 ScriptBundle을 BundleRelaxed로 바꾸십시오.

        bundles.Add(new BundleRelaxed("~/bundles/admin")
            .IncludeDirectory("~/Content/Admin", "*.js")
            .IncludeDirectory("~/Content/Admin/controllers", "*.js")
            .IncludeDirectory("~/Content/Admin/directives", "*.js")
            .IncludeDirectory("~/Content/Admin/services", "*.js")
            );


답변

오늘 같은 문제가 발생했는데 실제로 ~ / Scripts 아래의 일부 파일이 게시되지 않은 것을 발견했습니다. 누락 된 파일을 게시 한 후 문제가 해결되었습니다.


답변

또한 bundles.config 파일에 존재하지 않는 디렉토리가있어이 오류가 발생했습니다. 이것을 변경 :

<?xml version="1.0"?>
<bundleConfig ignoreIfDebug="true" ignoreIfLocal="true">
    <cssBundles>
        <add bundlePath="~/css/shared">
            <directories>
                <add directoryPath="~/content/" searchPattern="*.css"></add>
            </directories>
        </add>
    </cssBundles>
    <jsBundles>
        <add bundlePath="~/js/shared">
            <directories>
                <add directoryPath="~/scripts/" searchPattern="*.js"></add>
            </directories>
            <!--
            <files>
                <add filePath="~/scripts/jscript1.js"></add>
                <add filePath="~/scripts/jscript2.js"></add>
            </files>
            -->
        </add>
    </jsBundles>
</bundleConfig>

이에:

<?xml version="1.0"?>
<bundleConfig ignoreIfDebug="true" ignoreIfLocal="true">
    <cssBundles>
    </cssBundles>
    <jsBundles>
    </jsBundles>
</bundleConfig>

나를 위해 문제를 해결하십시오.


답변

@JerSchneid와 마찬가지로 내 문제는 빈 디렉토리 였지만 배포 프로세스는 OP와 달랐습니다. Kudu를 사용하는 Azure에서 git 기반 배포를 수행하고 있었지만 git이 저장소에 빈 디렉터리를 포함하지 않는다는 것을 알지 못했습니다. 참조 https://stackoverflow.com/a/115992/1876622를

그래서 내 로컬 폴더 구조는 다음과 같습니다.

[프로젝트 루트] / Content / jquery-plugins // 파일 있음

[프로젝트 루트] / Scripts / jquery-plugins // 파일 있음

[프로젝트 루트] / Scripts / misc-plugins // 빈 폴더

원격 서버에서 내 저장소의 복제 / 풀이 빈 디렉토리를 얻지 못했던 반면 :

[프로젝트 루트] / Content / jquery-plugins // 파일 있음

[프로젝트 루트] / Scripts / jquery-plugins // 파일 있음

이 문제를 해결하는 가장 좋은 방법은 빈 디렉터리에 .keep 파일을 만드는 것입니다. 이 SO 솔루션 참조 : https://stackoverflow.com/a/21422128/1876622


답변

나는 같은 문제가 있었다. 제 경우의 문제는 모든 부트 스트랩 / jqueries 스크립트가있는 스크립트 폴더가 wwwroot 폴더에 없다는 것입니다. 스크립트 폴더를 wwwroot에 추가하면 오류가 사라졌습니다.