I am really new to Dependency Injection and I am trying to have Json.Net deserialize a class the contains members that are Interfaces. I am receiving the following error.
"Could not create an instance of type IBioMetricCodeAttributes. Type is an interface or abstract class and cannot be instantiated."
The following is the class I am attempting to have Json.Net deserialize.
public sealed class EntryContract : IEntryContract
{
[JsonIgnore] public int EntryId { get; set; }
public string EntryTypeKey { get; set; }
public string ApplicationKey { get; set; }
public string PersonKey { get; set; }
public string ScreeningDateTime { get; set; }
[JsonIgnore] public int ApplicationId { get; set; }
[JsonIgnore] public int EntryTypeId { get; set; }
[JsonIgnore] public int? HealthProfileId { get; set; }
[JsonIgnore] public Guid ChangeSetId { get; set; }
[JsonIgnore] public DateTime EntryDate { get; set; }
[JsonIgnore] public DateTime SavedDate { get; set; }
[JsonIgnore] public string ExternalId { get; set; }
[JsonIgnore] public int OriginatingApplicationId { get; set; }
public List<IBioMetricCodeAttributes> CodeAttributes { get; set; }
public List<IBioMetricCountAttributes> CountAttributes { get; set; }
public List<IBioMetricDateAttributes> DateAttributes { get; set; }
public List<IBioMetricEnumAttributes> EnumAttributes { get; set; }
public List<IBioMetricFreeFormAttributes> FreeFormAttributes { get; set; }
public List<IBioMetricMeasurementAttributes> MeasurementAttributes { get; set; }
[JsonIgnore]
public List<IBioMetricXmlAttributes> XmlAttributes { get; set; }
}
My Ninject module is being loaded. It is as follows:
public class NexusModule : NinjectModule
{
public override void Load()
{
Bind<IBioMetricCodeAttributes>().To<BioMetricCodeAttributes>();
Bind<IBioMetricCountAttributes>().To<BioMetricCountAttributes>();
Bind<IBioMetricDateAttributes>().To<BioMetricDateAttributes>();
Bind<IBioMetricEnumAttributes>().To<BioMetricEnumAttributes>();
Bind<IBioMetricFreeFormAttributes>().To<BioMetricFreeFormAttributes>();
Bind<IBioMetricMeasurementAttributes>().To<BioMetricMeasurementAttributes>();
Bind<IBioMetricXmlAttributes>().To<BioMetricXmlAttributes>();
}
}
The error is being thrown at the following line of code.
return JsonConvert.DeserializeObject<List<EntryContract>>(GetBiometricData(nexusId, entryTypes));
I am using Newtonsoft.Json version 6.0 and Ninject version 3.2.2.
Any help on this would be appreciated.