Hello We could find a Solution:
The reason seems to be ASP.Net and the way it loads assemblies from your application directory for the first time and after a recycle. On first start, the assemblies are loaded from your application's bin directory and after a recycle (or even an IIS restart) it loads the assemblies from the Temporary ASP.NET Files directory. And depending on the situation more or less assemblies are loaded.
Her our Workaround (Not Nice but Works)
We load a new DLL in PreInitialize this will reload the Assemblies after Recygling:
Add a PreInitialize Entry in AssembliInfo.cs
[assembly: PreApplicationStartMethod(typeof(Nop.Web.Initializer), "BreakCache")]
Add a new Class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
using System.Web;
using System.Web.Compilation;
namespace Nop.Web
{
public static class Initializer
{
public static void BreakCache()
{
// start the assembly
string tempFolder = System.Threading.Thread.GetDomain().BaseDirectory;
var assemblyName = new AssemblyName { Name = "Cachebuster_" + DateTime.Now.ToString("yyyyMMddhhmmssfff") };
var filename = assemblyName.Name + ".dll";
var fullpath = tempFolder + @"\Plugins\" + filename;
// create our builders
var asmBuilder = Thread.GetDomain()
.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave, tempFolder + @"\Plugins\");
var fakeModule = asmBuilder
.DefineDynamicModule(assemblyName.Name, filename, true);
var typeBuilder = fakeModule
.DefineType(string.Format("WhoYaGonnaCall{0}", DateTime.Now.ToString("fff")), TypeAttributes.Public);
var fakeMethod = typeBuilder
.DefineMethod("Cachebusters", MethodAttributes.Public | MethodAttributes.Static);
// emit a minimum amount of IL
var methodIL = fakeMethod.GetILGenerator();
methodIL.Emit(OpCodes.Ret);
// create the type and save the DLL
typeBuilder.CreateType();
asmBuilder.Save(filename);
var assembly = Assembly.LoadFile(fullpath);
BuildManager.AddReferencedAssembly(assembly);
BuildManager.AddCompilationDependency(assembly.FullName);
}
}
}
Hope it helps for others that need a quick fix.
Regards
José