使用dotMemory进行内存分析时出现应用启动异常求助
Hey there! Let's work through this issue you're hitting with dotMemory and your .NET Core app. The error is straightforward—your application can't locate the wwwroot directory at the specified path, which is causing it to crash before dotMemory can even start profiling.
The Root Cause
Your app throws a System.IO.DirectoryNotFoundException because it can't find the wwwroot folder here:
D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\bin\Debug\netcoreapp2.2\wwwroot\
This happens during startup (specifically in Startup.cs line 155, where PhysicalFileProvider is initialized), killing the app before dotMemory can begin its analysis session.
Step-by-Step Fixes
Check if wwwroot exists in the output folder
Navigate to the path listed in the error and confirm if thewwwrootfolder is present. If it's missing, manually create an emptywwwrootfolder there first—this will get the app running temporarily while you fix the underlying issue.Ensure wwwroot is set to copy to output in your project
In Visual Studio:- Locate the
wwwrootfolder in your solution explorer - Right-click it and select Properties
- Set Copy to Output Directory to Copy always or Copy if newer
This guarantees the folder is copied to thebin/Debug/netcoreapp2.2directory every time you build your project.
- Locate the
Clean and rebuild your solution
Build caches can sometimes prevent files from updating correctly. Try:- Going to Build > Clean Solution to clear old output files
- Then Build > Rebuild Solution to generate fresh artifacts
- Attempt to run dotMemory profiling again after this.
Verify your Startup.cs configuration
Head to line 155 inStartup.cswhere the error originates. If you're manually initializing aPhysicalFileProvider, double-check that the path you're passing is correct. For most ASP.NET Core apps, the defaultapp.UseStaticFiles()automatically targetswwwroot—if you've modified this setup, confirm your path logic is accurate.
Full Error Log for Reference
应用启动异常: System.IO.DirectoryNotFoundException: D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\bin\Debug\netcoreapp2.2\wwwroot\ 在 Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) 在 Yara.PedEx.Administration.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, PedExDbContext dbContext) 位置 D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\Startup.cs:行号 155 --- 引发异常的上一位置的堆栈跟踪结束 --- 在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() 未处理的异常: System.IO.DirectoryNotFoundException: D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\bin\Debug\netcoreapp2.2\wwwroot\ 在 Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters) 在 Yara.PedEx.Administration.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, PedExDbContext dbContext) 位置 D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\Startup.cs:行号 155 --- 引发异常的上一位置的堆栈跟踪结束 --- 在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app) 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.StartAsync(CancellationToken cancellationToken) 在 Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token, String shutdownMessage) 在 Microsoft.AspNetCore.Hosting.WebHostExtensions.RunAsync(IWebHost host, CancellationToken token) 在 Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host) 在 Yara.PedEx.Administration.Program.Main(String[] args) 位置 D:\Projects\Source\PishroPostCloudLoyalty\pishropost-core\Yara.PedEx.Administration\Program.cs:行号 23
内容的提问来源于stack exchange,提问作者Parisa Partovinia

