web-dev-qa-db-ja.com

ディレクトリが存在しません。パラメーター名: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

どういう意味ですか ?

108
BjarkeCK

同じ問題が発生し、{バージョン}と*などのワイルドカードを使用して、存在しないファイルを指すバンドルがいくつかあることがわかりました。

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

それらをすべて削除すると、エラーはなくなりました。

221

これと同じ問題があり、コードの問題ではありませんでした。発行オプション(FTPオプションではない)を使用していましたが、Visual Studioは「プロジェクトに含まれていない」ため、スクリプト/ CSSの一部をAzureサーバーにアップロードしていませんでした。だから、ファイルは私のハードドライブにあったので、ローカルで問題なく動作しました。私の場合、この問題を解決したのは「プロジェクト>すべてのファイルを表示...」で、含まれていないファイルを右クリックし、それらを含めて再度公開します

16
dsnunez

これを簡単にするために書いた簡単なクラスを次に示します。

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

今日同じ問題に遭遇しましたが、実際には〜/ Scriptsの下のファイルの一部が公開されていないことがわかりました。不足しているファイルを公開した後、問題は解決しました

3
Naga

@JerSchneidと同様、私の問題は空のディレクトリでしたが、私の展開プロセスはOPとは異なりました。 Azure(Kuduを使用)で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

2
HeyZiko

また、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>

問題を解決してください。

2
JerSchneid

同じ問題がありました。私の場合の問題は、すべてのbootstrap/jqueriesスクリプトを含むスクリプトのフォルダーがwwwrootフォルダーにないことでした。スクリプトのフォルダーをwwwrootに追加すると、エラーはなくなりました。

2
rafaelzm2000

私も同じ問題に直面しました。スクリプトフォルダーの下のファイルパスを参照し、正確なファイル名をコピーしてbundle.csを変更しました。

古いコード://Bundle.cs

public class BundleConfig

{

    public static void RegisterBundles(BundleCollection bundles)

    {

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

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

    }
}

新しいコード:

public class BundleConfig

{

      public static void RegisterBundles(BundleCollection bundles)

      {

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

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate.js"));

        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-2.6.2.js"));
      }
}
1
Adityan s nair

これは、デプロイ中の競合状態によっても発生する可能性があります。

Visual Studioの「公開」を使用してネットワークファイル共有を介して展開し、「公開する前に既存のファイルをすべて削除する」にチェックマークを付ける場合。 (これは、プロジェクトから削除されたがサーバー上でハングアウトしているファイルに無意識に依存しないようにするために時々行います。)

必要なすべてのJS/CSSファイルが再デプロイされる前に誰かがサイトにアクセスすると、Application_StartおよびRegisterBundlesが開始され、バンドルの適切な構築とこの例外のスローに失敗します。

しかし、この例外が発生してサーバーをチェックするまでに、必要なファイルはすべて正しい場所にあります!

ただし、アプリケーションは喜んでサイトにサービスを提供し続け、これに起因するスタイル設定されていない/機能しないページとともに、すべてのバンドルリクエストに対して404を生成し、必要なJS/CSSファイルが利用可能になった後でもバンドルを再構築しようとしません。

「一致するファイルをローカルコピーに置き換える」を使用して再展開すると、アプリが再起動され、今回バンドルが適切に登録されます。

1
CrazyPyro

VS2015でVS2017プロジェクトを開き、ソリューションを構築してからDLLをアップロードしたときに、この問題が発生しました。

VS2017で再構築し、DLLを再アップロードすると、問題が修正されました。

1
Steve Woods

これは古い問題である可能性があります。同様のエラーがあり、私の場合は、ModelsフォルダーにScriptsフォルダーが隠れていました。スタックトレースは、欠落しているディレクトリを明確に示し、デフォルトでは、すべてのJavaスクリプトがScriptsフォルダーにある必要があります。これは、上記のユーザーには適用されない場合があります。

1
CuriousRK

新しいAngularアプリケーションを作成して作成しました

bundles.Add(new ScriptBundle("~/bundles/app")
    .IncludeDirectory("~/Angular", "*.js")
    .IncludeDirectory("~/Angular/directives/shared", "*.js")
    .IncludeDirectory("~/Angular/directives/main", "*.js")
    .IncludeDirectory("~/Angular/services", "*.js"));

ただし、servicesを作成していなかったため、servicesフォルダーは空であったため、公開時に展開されませんでした。残念ながら、公開するためには空のフォルダ内にダミーファイルを配置する必要があります

https://blogs.msdn.Microsoft.com/webdevelopertips/2010/04/29/tip-105-did-you-know-how-to-include-empty-directory-when-package-a- web-application /

1
tic

同じ質問がありました! IIS Expressのようです。プロジェクトライクのIIS Express 'URLを変更します。

"http://localhost:3555/"

その後、問題はなくなりました。

0
user2320546

私の問題は、私のサイトにバンドルするファイルがなかったことです。ただし、jQueryスクリプトを含むMVCテンプレートを使用してサイトを作成しました。 bundle.configは、これらのファイルとそのフォルダーを参照していました。スクリプトは必要ないので、削除しました。 bundle.configを編集した後は、すべて問題ありませんでした。

0
CraigP

基本的に、スタックトレースは、存在しないリソースを削除する必要がある正確な場所(スクリーンショットで強調表示)を提供します。

image showing stack trace

0

すべてが正常に機能していましたが、無関係な変更を行うと、次のビルドで同じ問題が発生しました。ソース管理を使用して以前のバージョンと比較し、私の../Content/Scriptsフォルダーが神秘的に空になっていることを発見しました!

バックアップから../Content/Scripts/*.*を復元し、すべて正常に機能しました!

ps:VS2012を使用して、MVC4は最近、いくつかのNuGetパッケージを更新したため、問題の一部を果たしているかもしれませんが、更新後しばらくはすべて正常に動作しました。

0
nspire

jsxファイルを奇妙な方法で作成したため、これらの回答はどれも役に立ちませんでした。私のコードはローカルホストモードで動作していましたが、本番では失敗しました。

私にとっての修正は、csprojファイルに移動し、ファイルパスを<None ...から<Content ...に変更することでした。

0
JacobIRR

BundleConfig.csクラスファイルから次のコード行を削除すると、私の課題が解決しました。

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

IncludeDirectory()を呼び出す行のBundleConfig.csファイルを調べます

すなわち:

  bundles.Add(new Bundle("~/bundle_js_angularGrid").IncludeDirectory(
                       "~/Scripts/Grid", "*.js", true));

グリッドディレクトリが存在しませんでした。

0
RolandoCC

アプリケーションを実行しているファイルがありません。プロジェクトをビルドして再アップロードしてみてください。または、バックアップがある場合は、バックアップから戻ってみてください。問題を解決します

0
Enes Gezici

また、分離したすべてのバンドルを1つのバンドルに結合したときに、このエラーが発生しました。

bundles.Add(new ScriptBundle("~/bundles/one").Include(
            "~/Scripts/one.js"));
bundles.Add(new ScriptBundle("~/bundles/two").Include(
            "~/Scripts/two.js"));

に変更

bundles.Add(new ScriptBundle("~/bundles/js").Include(
            "~/Scripts/one.js",
            "~/Scripts/two.js"));

この問題を解決するには、共有ホスティングのコントロールパネルでアプリケーションプールを更新する必要がありました。

0
rene anderson