Monday, August 01, 2011

Web Forms File Upload: 2 Exceptions [Common Errors]


If you are having trouble with the File Upload field within the Web Forms for Marketers module, specifically the form submission fails with a generic error, check your Sitecore log file. If you see either of the following two exceptions, there is a solution! Read on.

First exception:

4624 11:31:12 WARN  Object reference not set to an instance of an object.
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: Sitecore.Forms.Custom
at Sitecore.Form.UI.Adapters.FileUploadAdapter.AdaptResult(Object value)
at Sitecore.Form.Core.Utility.FieldReflectionUtil.GetAdaptedResult(ID fieldID, Object value)
at Sitecore.Form.Core.Controls.Data.AdaptedControlResult..ctor(ControlResult result, Boolean simpleAdapt)
at Sitecore.Form.Core.Submit.SubmitActionManager.AdaptResult(IEnumerable`1 list, Boolean simpleAdapt)
at Sitecore.Form.Core.Submit.SubmitActionManager.ExecuteSaving(ID formID, ControlResult[] list, ActionDefinition[] actions, Boolean simpleAdapt, ID sessionID)
at Sitecore.Form.Core.FormDataHandler.ProcessData(SimpleForm form, ControlResult[] fields, ActionDefinition[] actions)

4624 11:31:12 WARN  Web Forms for Marketers: an exception: Object reference not set to an instance of an object. has occured while trying to execute an action.
This is most likely happening because you have two server configuration (separated CD from CM) and master database removed as per the Scaling Guide. The error happens in case if you did not configure the remote WFM service as per section 2.11 “Multiple Sitecore Instances” within the reference doc: http://sdn.sitecore.net/upload/sdn5/products/web_forms2/web%20forms%20for%20marketers%20v2_2%20reference-a4.pdf
Simply add the connection string to the web service and make sure that the following setting on CD instance(s) is set to "web". This setting is defined within /App_Config/Include/forms.config file.
<!-- Sets the name of the master database  -->
<setting name="WFM.MasterDatabase" value="web"/>

Second exception:

2780 14:55:48 ERROR Could not save posted file: Desert.jpg
Exception: System.InvalidOperationException
Message: An instance of Sitecore.Data.Items.Item was null. Additional information: Could not create media folder: 'D/Sitecores/WFFM 21/Website/sitecore/media library'.
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsNotNull(Object value, Type type, String format, Object[] args)
   at Sitecore.Resources.Media.MediaCreator.CreateFolder(String itemPath, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateItem(String itemPath, String filePath, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, Boolean setStreamIfEmpty, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, MediaCreatorOptions options)
   at Sitecore.Form.Core.Media.MediaUploaderEx.UploadToDatabase(ICollection`1 list)
   at Sitecore.Form.Core.Media.MediaUploaderEx.Upload()
   at Sitecore.Form.Core.Pipelines.FormUploadFile.Save.Process(FormUploadFileArgs args)

2780 14:55:48 WARN  An instance of Sitecore.Data.Items.Item was null. Additional information: Could not create media folder: 'D/Sitecores/WFFM 21/Website/sitecore/media library'.
Exception: System.InvalidOperationException
Message: An instance of Sitecore.Data.Items.Item was null. Additional information: Could not create media folder: 'D/Sitecores/WFFM 21/Website/sitecore/media library'.
Source: Sitecore.Kernel
   at Sitecore.Diagnostics.Assert.IsNotNull(Object value, Type type, String format, Object[] args)
   at Sitecore.Resources.Media.MediaCreator.CreateFolder(String itemPath, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateItem(String itemPath, String filePath, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, Boolean setStreamIfEmpty, MediaCreatorOptions options)
   at Sitecore.Resources.Media.MediaCreator.CreateFromStream(Stream stream, String filePath, MediaCreatorOptions options)
   at Sitecore.Form.Core.Media.MediaUploaderEx.UploadToDatabase(ICollection`1 list)
   at Sitecore.Form.Core.Media.MediaUploaderEx.Upload()
   at Sitecore.Form.Core.Pipelines.FormUploadFile.Save.Process(FormUploadFileArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Form.UI.Adapters.FileUploadAdapter.AdaptResult(Object value)
   at Sitecore.Form.Core.Utility.FieldReflectionUtil.GetAdaptedResult(ID fieldID, Object value)
   at Sitecore.Form.Core.Controls.Data.AdaptedControlResult..ctor(ControlResult result, Boolean simpleAdapt)
   at Sitecore.Form.Core.Submit.SubmitActionManager.AdaptResult(IEnumerable`1 list, Boolean simpleAdapt)
   at Sitecore.Form.Core.Submit.SubmitActionManager.ExecuteSaving(ID formID, ControlResult[] list, ActionDefinition[] actions, Boolean simpleAdapt, ID sessionID)
   at Sitecore.Form.Core.FormDataHandler.ProcessData(SimpleForm form, ControlResult[] fields, ActionDefinition[] actions)

2780 14:55:48 WARN  Web Forms for Marketers: an exception: An instance of Sitecore.Data.Items.Item was null. Additional information: Could not create media folder: 'D/Sitecores/WFFM 21/Website/sitecore/media library'. has occured while trying to execute an action.

This error may happen if:
  • You are running WFM earlier than 2.2.0 rev. 110303
  • "Media.UploadAsFiles" setting is set to "true"
As you may have guessed, this issue was fixed in 2.2.0 rev. 110303.
Hope this helps.

2 comments:

Jake_F said...

Hi Alex,

We encountered the second error on one of our sites, however the option "Media.UploadAsFiles" was already set to "true".

As the website in question deals with multiple languages. I found the solution was very similar to the one you mentioned. I set the "Media.UploadAsVersionableByDefault" setting to "true" and this did the trick.

Jake_F said...

Hi Alex,

We encountered the second error on one of our sites, however the option "Media.UploadAsFiles" was already set to "true".

As the website in question deals with multiple languages. I found the solution was very similar to the one you mentioned. I set the "Media.UploadAsVersionableByDefault" setting to "true" and this did the trick.