Bug Relating to Overlapping Application Pool Recycling in IIS and Nopcommerce 4.1 UsePluginShadowCopy

10 months ago
[email protected] wrote:
I have copied the given Core dll.
Made shadowcopy = false

The site stopped working at all. Received error regarding dependent dlls not found. Then I copied respective DLLs to every respective plugin folder for which I as receiving errors. Do you think it was required or am I missing something?

It's important because I still have many many new issues, that's why I thought I should ask, maybe I am going in the wrong direction at all.


After copying the DLL over and making the flag change to "false" it's probably necessary to restart the application.  @foxnetsoft can confirm if this is necessary.

We have the change implemented in staging, but we haven't pushed out to production yet.  We should be able to provide feedback sometime in the future.
10 months ago
My team has followed your steps again in this way and didn't got such of those errors.

1- Make the app settings to default
2- Applied the given code above in the PluginManager.cs (Posted: February 18, 2019 at 10:01 PM by Foxnet)
3- Reduced regular interval time to see the effect quickly
4- We didn't use the given Nop.Core.Dll file as it as because we have a lot of our own entities to in it.

After a few hours, the app was down again twice with the following message both the times.



Application startup exception: System.Exception: Plugin 'Redirect Manager'. Access to the path 'C:\HostedApps\Coucou_Tunisia_v4_10\Plugins\bin\FoxNetSoft.Plugin.Misc.RedirectManager.dll' is denied.
Access to the path 'C:\HostedApps\Coucou_Tunisia_v4_10\Plugins\bin\FoxNetSoft.Plugin.Misc.RedirectManager.dll' is denied.
---> System.Exception: Plugin 'Redirect Manager'. Access to the path 'C:\HostedApps\Coucou_Tunisia_v4_10\Plugins\bin\FoxNetSoft.Plugin.Misc.RedirectManager.dll' is denied. ---> System.UnauthorizedAccessException: Access to the path 'C:\HostedApps\Coucou_Tunisia_v4_10\Plugins\bin\FoxNetSoft.Plugin.Misc.RedirectManager.dll' is denied.
   at System.IO.FileSystem.DeleteFile(String fullPath)
   at System.IO.File.Delete(String path)
   at Nop.Core.Plugins.PluginManager.ShadowCopyFile(String pluginFilePath, String shadowCopyPlugFolder)
   at Nop.Core.Plugins.PluginManager.PerformFileDeploy(String plug, ApplicationPartManager applicationPartManager, NopConfig config, String shadowCopyPath)
   at Nop.Core.Plugins.PluginManager.Initialize(ApplicationPartManager applicationPartManager, NopConfig config)
   --- End of inner exception stack trace ---
   at Nop.Core.Plugins.PluginManager.Initialize(ApplicationPartManager applicationPartManager, NopConfig config)
   --- End of inner exception stack trace ---
   at Nop.Core.Plugins.PluginManager.Initialize(ApplicationPartManager applicationPartManager, NopConfig config)
   at Nop.Web.Framework.Infrastructure.Extensions.ServiceCollectionExtensions.ConfigureApplicationServices(IServiceCollection services, IConfiguration configuration)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

-----------------------------------------------

As a result, we are having no different behavior as we were receiving in the start, Just app crashes on pool recycle restart.

Any help, please?
10 months ago
Did you use my compiled DLL file or you did your own one?
10 months ago
We did our own. As I mentioned in my previous reply, We have added many entities in core project that's why we can't use your given dll for testing.

What we did, we embedded your code (mentioned Fox team fix) in PluginManager.cs.
10 months ago
I show you how to copy the code from nop 4.20 to nop 4.10.
But I added some of new code in my DLL.
Before sending this code to nop team I want to investigate if my code solved the problem.
Please read this topic carefully.
10 months ago
@foxnetsoft
We have done these steps and I am showing you the code which we added.
Steps we have done:

1- Changed the code as you mentioned above. (I have also pasted it below).

private static Assembly PerformFileDeploy(string plug, ApplicationPartManager applicationPartManager, NopConfig config, string shadowCopyPath = "")
        {
            var parent = string.IsNullOrEmpty(plug) ? string.Empty : _fileProvider.GetParentDirectory(plug);

            if (string.IsNullOrEmpty(parent))
                throw new InvalidOperationException($"The plugin directory for the {_fileProvider.GetFileName(plug)} file exists in a folder outside of the allowed nopCommerce folder hierarchy");

            if (!config.UsePluginsShadowCopy)
            {
                //return RegisterPluginDefinition(config, applicationPartManager, plug);
                var assembly = RegisterPluginDefinition(config, applicationPartManager, plug);
                // delete the .deps file
                if (plug.EndsWith(".dll"))
                {
                    _fileProvider.DeleteFile(plug.Substring(0, plug.Length - 4) + ".deps.json");
                }

                return assembly;
            }
            

            //in order to avoid possible issues we still copy libraries into ~/Plugins/bin/ directory
            if (string.IsNullOrEmpty(shadowCopyPath))
                shadowCopyPath = _shadowCopyFolder;

            _fileProvider.CreateDirectory(shadowCopyPath);
            var shadowCopiedPlug = ShadowCopyFile(plug, shadowCopyPath);

            Assembly shadowCopiedAssembly = null;

            try
            {
                shadowCopiedAssembly = RegisterPluginDefinition(config, applicationPartManager, shadowCopiedPlug);
            }
            //nop team fix
            catch (UnauthorizedAccessException)
            {
                /*var fileProvider = EngineContext.Current.Resolve<INopFileProvider>();
                //suppress exceptions for "locked" assemblies, try load them from another directory
                if (!config.CopyLockedPluginAssembilesToSubdirectoriesOnStartup ||
                    !shadowCopyPath.Equals(fileProvider.MapPath(NopPluginDefaults.ShadowCopyPath)))
                {
                    throw;
                }*/

                if (!config.CopyLockedPluginAssembilesToSubdirectoriesOnStartup || !shadowCopyPath.Equals(_shadowCopyFolder))
                    throw;
            }
            //end nop team fix
            catch (FileLoadException)
            {
                if (!config.CopyLockedPluginAssembilesToSubdirectoriesOnStartup || !shadowCopyPath.Equals(_shadowCopyFolder))
                    throw;
            }

            return shadowCopiedAssembly ?? PerformFileDeploy(plug, applicationPartManager, config, _reserveShadowCopyFolder);
        }



2- Made UsePluginShadowCopy true. rest of the settings are the default.

The application started well but it crashed with the same error message of accesss denied after a few hours.

Then I changed the UsePluginShadowCopy=false as @alldogsoffroad mentioned. This time application even didn't start and start sowing me error given below


------
Application startup exception: System.Exception: Plugin 'Nop One Page Checkout'. Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

Unable to load one or more of the requested types.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Could not load file or assembly 'SevenSpikes.Nop.Framework, Version=4.1.446.28460, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
--------

2 Days ago, we started copying required dlls into the respectie plugin folder which was showing error. By doing that way the application started well but all the plugins were actually not working.
10 months ago
I was right.
You used my code (I moved it from nop 4.20 to 4.10). Nop team did very good job.
But I added extra code in my compiled DLL.
You didn't try my DLL. Try it.
9 months ago
hi foxnetsoft,

my website is busrapirlanta.com.tr and am having the same issue. I am unfamiliar with nopcommerce overall so could not wrap my head around the whole solution. Could you please clarify the exact steps?

Backup old DLL and try this new one http://foxnetsoft.com/content/files/Nop.Core.dll.zip
1- Where is the old DLL located?
2- Is this DLL compiled? Should I just copy paste or do I need to do uncompile or compile etc?
3- Is there any other steps required other than replacing the DLL and restarting the VPS?

Many thanks for the solution!
9 months ago
This dll file is in nop store folder.
Replace only dll. That's all.
9 months ago
I am having an authorization error, I am connecting with Administrator and have changed the security settings to my user Administrator however still can not replace the file, could you tell how can I overcome this?