"System.ArgumentException: Argument 'file.Extension' may not be null or empty" when uploading a file without an extension using File Attachment control
kbt161989
PRODUCTIssue
When attempting to upload a file without an extension using the File Attachment control causes exception and a restart of the SmartForms application pool.Symptoms
You may see Event ID 1325 of Error Level logged in Application log with the following details:
FileUtility.StoreFileToRemoteServer(File=FileNameWithoutExtension, Hash=2B5CC1B9357729EC5731B01611E70275). Exception: System.ArgumentException: Argument 'file.Extension' may not be null or empty Parameter name: file.Extension at SourceCode.Forms.Management.ThrowHelper.ArgumentNullOrEmpty(String parameterName) at SourceCode.Forms.Management.FormsManager.SetFile(FileInfo file) at SourceCode.Forms.AppFramework.FileUtility.StoreFileToRemoteServer(FileInfo file, Stream stream, Int32 fileLength)
Log Name: Application
Event ID: 1325
Level: Error
Source: ASP.NET 4.0.30319.0
Sample error message screenshot:
Resolution
This is a known issue which has been addressed in K2 4.7 March 2018 Cumulative Update Fix Pack 38.
Without FP38 installed, attempting to upload a file without an attachment is blocked. When you select the file, you receive a "File not uploaded. Details." error message, with the following explanation available after clicking on Details: "The file attachment has no extension. Select a file with a valid extension."
This prevents an unhandled exception of the IIS application pool. A possible workaround which can be used until FP38 is not installed, is to use an extensions blacklist. You just need to put 2 commas (",,") into the Runtime web.config as Forms.Designer.Controls.Attachment.Blacklist value, i.e:
%FileName% File not uploaded Details.
Details: This type of file may not be attached.
Sample message screenshot:
This also prevents unhandled exceptions. In addition to this, in control properties there is an Allowed Types property which allows you to specify a limited set of allowed extensions which will dictate what will be targeted by Windows Explorer open file dialog (i.e. it will be showing only those file extensions by default), though user still can change this in the drop-down. Use of this setting greatly reduces the possibility of uploading a file with no extension by accident.
It also adds a "Valid extensions are:" line which lists allowed extensions to the error message details:
You may also consider adding a data label with red text instructing users to upload only specific extensions if necessary:
The recommended resolution is to download and install the appropriate update:
For K2 4.7 - K2 4.7 March 2018 Cumulative Update Fix Pack 38 or newer. See KB002967 for details.
For K2 5.0 - Upgrade to newer versions of K2 listed below.
For K2 5.1 - K2 Five (5.1) November 2018 Cumulative Update Fix Pack 7. See KB002969 for details.
For K2 5.2 - K2 Five (5.2) Fix Pack 21 or newer. See KB002973 for details.