We are going to investigate the following issue in this blog post
Exception handed to HandleRuntimeException.HandleException System.ArgumentException: Input string was not in a correct format.Couldn’t store <Veyron> in Model Column. Expected type is Int32. —> System.FormatException: Input string was not in a correct format.
Right, what do we have this time…
We can see there is an error with the ‘Model’ column, it looks like we tried to pass in the value of “Veryon” but SharePoint was expecting an Int32. Lets get all CSI:SharePoint ….
If you have read any of the other BCS Error blog posts you hopefully would have learnt that SharePoint has come to expect an Int32 because we have a TypeDescriptor telling it that the ‘Model’ TypeDescriptor is of type Int32, lets have a look.
ahh yes, We can see the offending value. Lets check our SupercarEntity class and see what type it should be set to.
namespace LightningTools.TheTestBcsModel.BdcModel1 { public class SupercarEntity { public int CarId { get; set; } public string Manufacturer { get; set; } public string Model { get; set; } public uint TopSpeed { get; set; } public TimeSpan ZeroToSixtyTime { get; set; } public uint HorsePower { get; set; } public decimal Price { get; set; } } }
In the above code we can see that ‘Model’ is in fact a ‘string’.
So what’s happening here is that SharePoint, when rendering the Web Part, is getting a SupercarEntity passed to it and it’s then trying to convert the ‘Model’ name (in our example “Veyron”) into an Int32 and it’s failing.
How to Fix
Select the TypeDescriptor in the BDC Explorer (as above) and change it’s type to ‘System.String’ to match the ‘Model’ property type in our C# code.
Deploy.
Rejoice.