JSON Exception when removing email server

I went to the SMTP settings and cleared out the previously populated fields. I get an exception on saving of:

Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.Int32'. Path 'SmtpPort', line 1, position 40. ---> System.InvalidCastException: Null object cannot be converted to a value type.
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Bind[TModel]() in Y:\work\refs\tags\3.3.4\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 72
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.BindAndValidate[TModel]() in Y:\work\refs\tags\3.3.4\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 77
   at Octopus.Server.Web.Api.Actions.SmtpConfigurationUpdateAction.Execute() in Y:\work\refs\tags\3.3.4\source\Octopus.Server\Web\Api\Actions\SmtpConfigurationUpdateAction.cs:line 24
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Respond(TDescriptor options, NancyContext context) in Y:\work\refs\tags\3.3.4\source\Octopus.Server\Web\Infrastructure\Api\Responder.cs:line 162
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at CallSite.Target(Closure , CallSite , Object , Object , NancyContext )
   at Octopus.Server.Web.Api.OctopusRestApiModule.<>c__DisplayClass0_0.<.ctor>b__0(Object o) in Y:\work\refs\tags\3.3.4\source\Octopus.Server\Web\Api\OctopusRestApiModule.cs:line 46
   at CallSite.Target(Closure , CallSite , Func`2 , Object )
   at Nancy.Routing.Route.<>c__DisplayClass4.<Wrap>b__3(Object parameters, CancellationToken context)

Hi,

Thanks for getting in touch! I have replicated the problem and confirmed that this is a bug, thank you for reporting this. Here is the issue you can track: https://github.com/OctopusDeploy/Issues/issues/2506.
As a work-around, entering a “0” in the SMTP Port field with all other fields cleared should allow you to successfully save.

Hope that helps!

Mark