1

I have a Sitecore task that generates a package of a specific set of content to export and then import to another instance.

This task uses some pretty generic code and works in other environments but does not in production. The package designer in the UI is also failing with the same error so I know this is not my code. The code is failing in the package generation method in the Sitecore.Kernel.dll with the dreaded The file exists error.

I have checked all temp directories including .net temp files, C:\Windows\Temp (which I have verified is the directory that the app is using), and C:\temp\packages (the directory I am writing the package to for the API to be able to access). I have also verified that all directories in the app pool have read/write/modify access to all directories in question.

There are 0, and I mean zero files in these directories. I do see that when I run my code a temp file does get created but then it immediately errors out with the File Exists error. If anyone has any idea what I can do at this point I am grasping at straws!

Code calling:

using (new global::Sitecore.SecurityModel.SecurityDisabler())
            {
                using (var writer = new PackageWriter(MainUtil.MapPath(fileName)))
                {
                    Context.SetActiveSite("shell");

                writer.Initialize(Installer.CreateInstallationContext());
                Log.Error("LocationDetailExportRepo: PackageGenerator.GeneratePackage", this);
                PackageGenerator.GeneratePackage(packageProject, writer);

                Context.SetActiveSite("website");
            }
        }

Error stack:

    ManagedPoolThread #18 12:32:17 ERROR LocationDetailExportRepo: Error with building export package System.IO.IOException: The file exists.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Path.InternalGetTempFileName(Boolean checkHost)
at Sitecore.Zip.ZipWriter..ctor(String outputFile, Encoding encoding)
at Sitecore.Install.Zip.PackageWriter.Initialize()
at Sitecore.Install.Zip.PackageWriter.Put(PackageEntry entry)
at Sitecore.Install.PackageGenerator.GeneratePackage(PackageProject solution, ISink`1 writer)
at ihc.org.DataAccess.LocationDetailExport.LocationDetailExportRepo.PackageLocationData() in C:\work\repo\ihc.org.DataAccess\LocationDetailExport\LocationDetailExportRepo.cs:line 111 at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Path.InternalGetTempFileName(Boolean checkHost)
at Sitecore.Zip.ZipWriter..ctor(String outputFile, Encoding encoding)
at Sitecore.Install.Zip.PackageWriter.Initialize()
at Sitecore.Install.Zip.PackageWriter.Put(PackageEntry entry)
at Sitecore.Install.PackageGenerator.GeneratePackage(PackageProject solution, ISink`1 writer)
at ihc.org.DataAccess.LocationDetailExport.LocationDetailExportRepo.PackageLocationData() in C:\work\repo\ihc.org.DataAccess\LocationDetailExport\LocationDetailExportRepo.cs:line 111
5
  • 1
    Can you please share log?
    – Alexander
    Apr 8, 2022 at 22:12
  • did you clear your user's temp folder? - C:\Users\YOURUSERNAME\AppData\Local\Temp Apr 11, 2022 at 10:07
  • Can you share the logs and your code snippet? Apr 12, 2022 at 1:01
  • Added error stack and code snippet of the package creation. As I stated, this is also failing when using the sitecore package designer with the same error (minus being called from our pipeline of course). This works in all environments but prod and I have removed the task entirely to see if it was causing any weirdness too. Apr 12, 2022 at 12:14
  • @MahendraShekhawat this is the iis app pool so it is using c:\windows\temp folder. There is nothing there. I did take the nuclear approach and deleted all users temp directories too. There is nothing in any temp directory and really never was (aside from a handful of log files from other applications). Apr 12, 2022 at 13:01

1 Answer 1

1

The method System.IO.Path.InternalGetTempFileName() will attempt to create a file in the folder returned by System.IO.Path.GetTempPath() using a Win32Native command. If this command fails your will get the IOError you are seeing, which might lead us to one of the following conclusions:

  • The web application does not have write access to the folder it's trying to create the file in
  • The web application has write access, but not read access
  • There are so many files in the target folder that it's not possible for the Temp File Generation system to add a new one

Seeing as you've already checked most of these we should conclude that the system is not writing to the place you think it's writing to.

When I need to test this sort of thing quickly I create a test.aspx file in the root of the solution which I can add some "code beside" into to execute some commands and return some trace data to the screen. You can use this technique and flex some WebForms Skillz(TM) to verify the path returned by System.IO.Path.GetTempPath() which is public, where the method cited in the stack is private and can't be (easily) called directly. If you want to be very tricksy you can use reflection to execute this private method.

There is a public version of the System.IO.Path.GetTempFileName() which calls the Internal method with true as an argument. You could verify the arguments that Sitecore is using, but seeing as it's not "System" it's probably also using this public method so that would be a good test. A try/catch might reveal some additional data in InnerExceptions from Win32 that would provide more clues.

Lastly you can install SysInternals Process Monitor. It's EXTREMELY noisy so keep it disabled till the last second then enable it, run your test page, and immediately disable it again. You'll still have 32,000 events per second but if you narrow down to failed file system events you might get lucky and capture the event that causing the failure.

PS: If your app pool is 32-bit instead of 64-bit you might need to look at C:\Windows\SysWOW64 instead of C:\Windows\System32 even if System32 is reported in your telemetry, as this path is symlinked in to replace System32 for compatibility with 32-bit apps under various circumstances.

2
  • So I have verrified that it is indeed using the c:\windows\temp directory. The iis app pool user has complete control over that directory (I have also granted Everyone access to it as well just to test things out). I have placed extensive logging in my custom code and it all behaves normally till the call to create the package. Oddly enough, the code will create a temp file but then fail immediately after. Apr 12, 2022 at 14:42
  • 1
    So your answer got me thinking more about our Mid tier team. They had, at some point in the past, changed the user that the app pool was running under. It was running under network service not the app pool's identity. Apparently granting permissions to "Everyone" does not include network service. I changed the user to run under the app pools identity and it started working. Apr 12, 2022 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.