Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentOutOfRangeException: The DateTimeOffset specified cannot be converted into a Zip file timestamp #2803

Closed
harrison314 opened this issue Jun 11, 2020 · 8 comments · Fixed by #2804
Assignees
Labels
Milestone

Comments

@harrison314
Copy link

How Did You Get This To Happen? (Steps to Reproduce)

  • Publish ASP.Net Core 3.1 project to publish directory.
  • ZIP Directory

Example code:

string publishPath = "./publishDir";
string buildOutput = "./Release";
Task("Build-Example")
    .Does(()=>
    {
        DotNetCorePublishSettings settings = new DotNetCorePublishSettings()
        {
            Configuration = configuration,
            NoDependencies = false,
            NoRestore = false,
            OutputDirectory = publishPath,
            MSBuildSettings = new DotNetCoreMSBuildSettings()
        };

        CleanDirectory(publishPath);
        DotNetCorePublish("../src/ExampleAspnetCore31.csproj", settings);

        Zip(publishPath, $"{buildOutput}/ExampleAspnetCore31.zip");
    })
    .Finally(() =>
    {  
        DeleteDirectory(publishPath, new DeleteDirectorySettings() 
        {
            Recursive = true,
            Force = true
        });
    });

Output Log

Error: System.AggregateException: One or more errors occurred. ---> System.ArgumentOutOfRangeException: The DateTimeOffset specified cannot be converted into a Zip file timestamp.
Parameter name: value
   at System.IO.Compression.ZipArchiveEntry.set_LastWriteTime(DateTimeOffset value)
   at Cake.Common.IO.Zipper.Zip(DirectoryPath rootPath, FilePath outputPath, IEnumerable`1 paths)
   at Submission#0.Zip(DirectoryPath rootPath, FilePath outputPath) in :line 2423
   at Submission#0.<<Initialize>>b__0_6() in D:\Dev\QES_Portal\QESPortal\build\build.cake:line 158
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass32_0.<Does>b__0(ICakeContext x)
   at Cake.Core.CakeTask.<Execute>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.DefaultExecutionStrategy.<ExecuteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.CakeEngine.<RunTask>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<RunTargetAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Scripting.BuildScriptHost.<RunTargetAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
   at Submission#0.<<Initialize>>d__0.MoveNext() in D:\Dev\QES_Portal\QESPortal\build\build.cake:line 659
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.<RunSubmissionsAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Scripting.Script`1.<RunSubmissionsAsync>d__21.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script)
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
   at Cake.Commands.BuildCommand.Execute(CakeOptions options)
   at Cake.CakeApplication.Run(CakeOptions options)
   at Cake.Program.Main()
---> (Inner Exception #0) System.ArgumentOutOfRangeException: The DateTimeOffset specified cannot be converted into a Zip file timestamp.
Parameter name: value
   at System.IO.Compression.ZipArchiveEntry.set_LastWriteTime(DateTimeOffset value)
   at Cake.Common.IO.Zipper.Zip(DirectoryPath rootPath, FilePath outputPath, IEnumerable`1 paths)
   at Submission#0.Zip(DirectoryPath rootPath, FilePath outputPath) in :line 2423
   at Submission#0.<<Initialize>>b__0_6() in D:\Dev\QES_Portal\QESPortal\build\build.cake:line 158
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass32_0.<Does>b__0(ICakeContext x)
   at Cake.Core.CakeTask.<Execute>d__43.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.DefaultExecutionStrategy.<ExecuteAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<ExecuteTaskAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.CakeEngine.<RunTask>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Cake.Core.CakeEngine.<RunTargetAsync>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Scripting.BuildScriptHost.<RunTargetAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
   at Submission#0.<<Initialize>>d__0.MoveNext() in D:\Dev\QES_Portal\QESPortal\build\build.cake:line 659
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.<RunSubmissionsAsync>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Scripting.Script`1.<RunSubmissionsAsync>d__21.MoveNext()<---

Simmilar problem OrchardCMS/OrchardCore#4477.

My workeround

        // ...
        var now = DateTime.UtcNow;
        foreach(var file in GetFiles($"{publishPath}/**/*.*"))
        {
            System.IO.File.SetLastWriteTimeUtc(file.FullPath, now);
        }
        Zip(publishPath, $"{buildOutput}/ExampleAspnetCore31.zip");
@devlead
Copy link
Member

devlead commented Jun 11, 2020

Ok, this would seem to be because of an issue with source files, but ideally, Cake shouldn't cause an exception here.
I'll submit a fix for this shortly.

@devlead devlead added the Bug label Jun 11, 2020
@devlead devlead added this to the v0.38.3 milestone Jun 11, 2020
@devlead devlead self-assigned this Jun 11, 2020
devlead added a commit to devlead/cake that referenced this issue Jun 11, 2020
devlead added a commit to devlead/cake that referenced this issue Jun 12, 2020
gep13 added a commit that referenced this issue Jun 12, 2020
GH2803: Ensure Valid Zip LastWriteTime
@gep13 gep13 closed this as completed Jun 12, 2020
@cake-build-bot
Copy link

🎉 This issue has been resolved in version v0.38.3 🎉

The release is available on:

Your GitReleaseManager bot 📦🚀

devlead added a commit that referenced this issue Jun 26, 2020
@Sobieck
Copy link

Sobieck commented Jul 20, 2020

I'm still getting this error when running 0.38.4. When I use the workaround detailed in this issue the issue is resolved.

@gep13
Copy link
Member

gep13 commented Jul 20, 2020

Do you have an example zip file that is causing this problem?

@Sobieck
Copy link

Sobieck commented Jul 20, 2020

I believe these are the files causing the problems.

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       12/31/1979  11:00 PM          20344 Microsoft.Extensions.Caching.Abstractions.dll
-a----       12/31/1979  11:00 PM          17272 Microsoft.Extensions.Caching.Memory.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.Configuration.Abstractions.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.Configuration.Binder.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Configuration.CommandLine.dll
-a----       12/31/1979  11:00 PM          18808 Microsoft.Extensions.Configuration.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.Configuration.EnvironmentVariables.dll
-a----       12/31/1979  11:00 PM          16760 Microsoft.Extensions.Configuration.FileExtensions.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Configuration.Ini.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Configuration.Json.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Configuration.KeyPerFile.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.Configuration.UserSecrets.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.Configuration.Xml.dll
-a----       12/31/1979  11:00 PM          20344 Microsoft.Extensions.DependencyInjection.Abstractions.dll
-a----       12/31/1979  11:00 PM          16760 Microsoft.Extensions.DependencyInjection.dll
-a----       12/31/1979  11:00 PM          17272 Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions.dll
-a----       12/31/1979  11:00 PM          17784 Microsoft.Extensions.Diagnostics.HealthChecks.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.FileProviders.Abstractions.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.FileProviders.Composite.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.FileProviders.Embedded.dll
-a----       12/31/1979  11:00 PM          17784 Microsoft.Extensions.FileProviders.Physical.dll
-a----       12/31/1979  11:00 PM          20856 Microsoft.Extensions.FileSystemGlobbing.dll
-a----       12/31/1979  11:00 PM          19832 Microsoft.Extensions.Hosting.Abstractions.dll
-a----       12/31/1979  11:00 PM          18808 Microsoft.Extensions.Hosting.dll
-a----       12/31/1979  11:00 PM          18808 Microsoft.Extensions.Http.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.Localization.Abstractions.dll
-a----       12/31/1979  11:00 PM          18296 Microsoft.Extensions.Localization.dll
-a----       12/31/1979  11:00 PM          19832 Microsoft.Extensions.Logging.Abstractions.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Logging.Configuration.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Logging.Console.dll
-a----       12/31/1979  11:00 PM          14712 Microsoft.Extensions.Logging.Debug.dll
-a----       12/31/1979  11:00 PM          17784 Microsoft.Extensions.Logging.dll
-a----       12/31/1979  11:00 PM          15736 Microsoft.Extensions.Logging.EventLog.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.Logging.EventSource.dll
-a----       12/31/1979  11:00 PM          15224 Microsoft.Extensions.Logging.TraceSource.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.ObjectPool.dll
-a----       12/31/1979  11:00 PM          16248 Microsoft.Extensions.Options.ConfigurationExtensions.dll
-a----       12/31/1979  11:00 PM          14712 Microsoft.Extensions.Options.DataAnnotations.dll
-a----       12/31/1979  11:00 PM          27512 Microsoft.Extensions.Options.dll
-a----       12/31/1979  11:00 PM          22392 Microsoft.Extensions.Primitives.dll
-a----       12/31/1979  11:00 PM          16760 Microsoft.Extensions.WebEncoders.dll
-a----       12/31/1979  11:00 PM          17784 Microsoft.JSInterop.dll

@devlead
Copy link
Member

devlead commented Jul 20, 2020

@Sobieck wonder if it's a time zone issue, could you please open an new issue with what Cake.exe --version outputs, which OS your running and what diagnostic output gives.

@Sobieck
Copy link

Sobieck commented Jul 20, 2020

Will do. Thanks for your help. I love the work you all do.

@devlead
Copy link
Member

devlead commented Jul 20, 2020

Will do. Thanks for your help. I love the work you all do.

Thanks @Sobieck, please mention in issue which time zone is local for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants