Temporary files asp.net resx files, “item with the

2019-07-18 02:46发布

问题:

A few weeks back we updated our servers from .NET 4.5 to 4.5.1 and also changed the code to run as "optimzed code"

During the nexcoming release we started to get a wierd error message in the logs (and also the site just crashed)

System.ArgumentException: An item with the same key has already been added.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
   at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture)
   at System.Web.Compilation.BaseResXResourceProvider.GetObject(String resourceKey, CultureInfo culture)
   at System.Web.Compilation.ResourceExpressionBuilder.GetResourceObject(IResourceProvider resourceProvider, String resourceKey, CultureInfo culture, Type objType, String propName)
   at System.Web.UI.TemplateControl.GetLocalResourceObject(String resourceKey)
   at ASP.masterpages_master_master.__BuildControlbritishLink() in c:\\Workspace\\MyApp\\Admin\\MasterPages\\Master.master:line 39
   at ASP.masterpages_master_master.__BuildControlheaderPanel() in c:\\Workspace\\MyApp\\Admin\\MasterPages\\Master.master:line 35
   at ASP.masterpages_master_master.__BuildControlform1() in c:\\Workspace\\MyApp\\Admin\\MasterPages\\Master.master:line 27
   at ASP.masterpages_master_master.__BuildControlTree(masterpages_master_master __ctrl) in c:\\Workspace\\MyApp\\Admin\\MasterPages\\Master.master:line 1
   at ASP.masterpages_master_master.FrameworkInitialize() in c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Temporary ASP.NET Files\\admin\\dbad5a18\\4cede7d0\\App_Web_vk3fiqpm.0.cs:line 0
   at System.Web.UI.UserControl.InitializeAsUserControlInternal()
   at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)
   at System.Web.UI.MasterPage.get_Master()
   at System.Web.UI.MasterPage.ApplyMasterRecursive(MasterPage master, IList appliedMasterFilePaths)
   at System.Web.UI.Page.ApplyMasterPage()
   at System.Web.UI.Page.PerformPreInit()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

We are using .resx files for translations, first thought was that we have dublicated keys in the resex files but that wasnt the case. After some hours of investigation we couldnt get a clear picture of what was happening. So we started to recycle the Application Pools and that seamed to solve the problem for now.

We have never seen the problem in our development enviroment (until a few days back) what we did then was to delete all the temporary files

Get-ChildItem “C:\Windows\Microsoft.NET\Framework*\v*\Temporary ASP.NET Files” -Recurse | Remove-Item -Recurse

(as what it concerncs is that the .resx files is beeing compiled with the JIT compiler and saved in temporary files? Is this correct?) That fixed the error on our development enviroment, so we tried it on one of our production server as well, that fixed the error for a short while, but then camed back. We dont understand how that can work on our development server but not production when we have the same settings and versions of everything on both enviroments (we have compared)

Have someone had similar problems, and if yes, what have you done? We now have to monitor our servers and see, becuase from time to time the error appears, it's randomly and it dosent give us more information as I have provided here. We have turned on more logging but that dosent give us more to go on.

To clear things out the error now is randomly, we dont know when it appears or why, we dont have any more to go on. Can it be that the .resex files is beeing compiled differently when "optimized code" is on?
Suggestion what to do?