VideoFileFieldType.cs causes API Exception
Description
When you have an VideoFileFieldType attribute type on a Content Channel, the api will give an exception when the attribute has a value. Background is Fellowship Greenville is pulling all the content channels Items for an external feed and when the Content Channel Item has a video file the API will log a silent exception.
Root cause is a typo in the VideoFileFieldType.cs file mentioned at the end
Actual Behavior
Adding the attribute to the Content Channel and adding a video to the attribute. The API will log the below silent exception:
Video Attribute on Content Channel:
Exception:
{ "Message": "An error has occurred.", "ExceptionMessage": "Error getting value from 'ValueFormatted' on 'Rock.Web.Cache.AttributeValueCache'.", "ExceptionType": "Newtonsoft.Json.JsonSerializationException", "StackTrace": " at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at Rock.Utility.RockJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding) in \\Rock\\Utility\\RockJsonMediaTypeFormatter.cs:line 249\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.WebHost.HttpControllerHandler.<WriteBufferedResponseContentAsync>d__1b.MoveNext()", "InnerException": { "Message": "An error has occurred.", "ExceptionMessage": "Input string was not in a correct format.", "ExceptionType": "System.FormatException", "StackTrace": " at System.Text.StringBuilder.FormatError()\r\n at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)\r\n at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)\r\n at Rock.Field.Types.VideoFileFieldType.GetHtmlValue(String privateValue, Dictionary2 privateConfigurationValues) in \Rock\Field\Types\VideoFileFieldType.cs:line 85\r\n at Rock.Web.Cache.AttributeValueCache.get_ValueFormatted() in \Rock\Web\Cache\NonEntities\AttributeValueCache.cs:line 162\r\n at GetValueFormatted(Object )\r\n at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)"
}
}`
Expected Behavior
I would expect the File Link to be in the returned JSON object in the API
Steps to Reproduce
- Configure a 'Content Channel'
- Add an Video File Attribute
- Navigate to the content Channel to upload a vide to the attribute
- Hit the API endpoint that will have that video field type and select "Expanded" for the loadattributes option:
The Solution that fixed FG:
Root cause is a typo located on line 157 with and extra } https://github.com/SparkDevNetwork/Rock/blob/5d87029b8bceab99cfb6cd50b24303a4291519d0/Rock/Field/Types/VideoFileFieldType.cs#L157
Removing the below typo fixes the API call from giving an exception.
Issue Confirmation
- [x] Perform a search on the Github Issues to see if your bug or enhancement is already reported.
- [x] Reproduced the problem on a fresh install or on the demo site.
Rock Version
1.16.6.9
Client Culture Setting
en-US