Some code:
BinaryReader reader;
//...
JournalEntry.Instantiate((JournalEntry.JournalEntryType)reader.ReadByte(), reader)
JournalEntry:
public enum JournalEntryType {
Invalid,
Tip,
Death,
Level,
Friend
}
private readonly static Dictionary<JournalEntryType, Type> instantiationBindings = new Dictionary<JournalEntryType, Type>() {
{JournalEntryType.Invalid, typeof(JournalEntryOther)},
{JournalEntryType.Tip, typeof(JournalEntryTip)},
{JournalEntryType.Death, typeof(JournalEntryOther)},
{JournalEntryType.Level, typeof(JournalEntryOther)},
{JournalEntryType.Friend, typeof(JournalEntryOther)}
};
internal JournalEntry(BinaryReader reader) {
Read(reader);
}
internal static JournalEntry Instantiate(JournalEntryType type, BinaryReader reader) {
return (JournalEntry)Activator.CreateInstance(instantiationBindings[type], reader);;
}
JournalEntryTip:
internal JournalEntryTip(BinaryReader reader) {
Read(reader);
}
The code at the very top is invoked with a byte of value 1, mapped to JournalEntryType.Tip
.
When I try to run this code, it throws System.MissingMethodException: 'Constructor on type 'JournalEntryTip' not found.'
Why is that? The constructor exists and should be invoked with the right argument.