I have Nopcommerce installed with pictures stored in database. After that I changed to file system and I got error when I first open any product. It looks like many processes try to create/update same file image.
System.IO.IOException: The process cannot access the file 'C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Presentation\Nop.Web\wwwroot\images\0000036_0.jpeg' because it is being used by another process.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
at System.IO.File.OpenHandle(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize)
at System.IO.File.<WriteAllBytesAsync>g__Core|92_0(String path, Byte[] bytes, CancellationToken cancellationToken)
at Nop.Core.Infrastructure.NopFileProvider.WriteAllBytesAsync(String filePath, Byte[] bytes) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Core\Infrastructure\NopFileProvider.cs:line 566
at Nop.Services.Media.PictureService.SavePictureInFileAsync(Int32 pictureId, Byte[] pictureBinary, String mimeType) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Media\PictureService.cs:line 108
at Nop.Services.Media.PictureService.UpdatePictureAsync(Int32 pictureId, Byte[] pictureBinary, String mimeType, String seoFilename, String altAttribute, String titleAttribute, Boolean isNew, Boolean validateBinary) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Media\PictureService.cs:line 973
at Nop.Services.Media.PictureService.GetPictureUrlAsync(Picture picture, Int32 targetSize, Boolean showDefaultPicture, String storeLocation, PictureType defaultPictureType) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Media\PictureService.cs:line 585
at Nop.Web.Factories.ProductModelFactory.<>c__DisplayClass53_0.<<PrepareProductDetailsPictureModelAsync>b__0>d.MoveNext() in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 1273
--- End of stack trace from previous location ---
at Nop.Core.Caching.MemoryCacheManager.GetAsync[T](CacheKey key, Func`1 acquire) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Core\Caching\MemoryCacheManager.cs:line 123
at Nop.Web.Factories.ProductModelFactory.PrepareProductDetailsPictureModelAsync(Product product, Boolean isAssociatedProduct) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 1242
at Nop.Web.Factories.ProductModelFactory.PrepareProductDetailsModelAsync(Product product, ShoppingCartItem updatecartitem, Boolean isAssociatedProduct) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Presentation\Nop.Web\Factories\ProductModelFactory.cs:line 1607
at Nop.Web.Controllers.ProductController.ProductDetails(Int32 productId, Int32 updatecartitemid) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Presentation\Nop.Web\Controllers\ProductController.cs:line 234
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Nop.Services.Authentication.AuthenticationMiddleware.InvokeAsync(HttpContext context) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 94
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 121
at WebMarkupMin.AspNetCore7.WebMarkupMinMiddleware.InvokeCore(HttpContext context, Boolean useMinification, Boolean useCompression)
at WebMarkupMin.AspNetCore7.WebMarkupMinMiddleware.InvokeCore(HttpContext context, Boolean useMinification, Boolean useCompression)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Nop.Services.Installation.InstallUrlMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Installation\InstallUrlMiddleware.cs:line 52
at Nop.Services.Common.KeepAliveMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\Users\SSM\source\Workspaces\NopCommerce\nopCommerce461\src\Libraries\Nop.Services\Common\KeepAliveMiddleware.cs:line 49
at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.InvokeCore(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|8_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
The second problem, when I added new image for a product, I think it should save the new image to file system and in table picture will be the VirtualPath of the new image, but it saved new binary content to table picturebinary.
Thank you for your help,
Page