Note: This is not answerable by What is a NullReferenceException, and how do I fix it?
I came across a strange error right now. My call of Int32.TryParse(string, out int)
is giving me a System.NullReferenceException
.
The idea is pretty simple - replace a metadata entry with a technical representation, rather than using an integer value:
public void GenerateClipName()
{
// Copy metadata entries, to prevent modifications on the actual viewmodel
var metadataEntries = ViewModel.MasterObject.MetadataEntries.Copy();
// Get the correct entry
var entry = metadataEntries.Single(m => m.Key.EndsWith("/" + MetaDataKeys.TITLE));
// Get all valid entries for the metadata key
var validEntries = MetadataDefinitions.Single(x => x.Id.EndsWith("/" + MetaDataKeys.TITLE));
int parsedInt;
// Try to parse the integer value, and replace it with the technical representation
if (int.TryParse(entry.Value, out parsedInt))
entry.Value = validEntries.ValidEntries.Single(m => m.Value == parsedInt).TechnicalRepresentation;
// Some further actions will be implemented here later
}
But the "expected output" is more like an "unexpected output":
As you can see in the Locals window below the editor window: the value of entry.Value
is "86".
EDIT #1:
As requested, the variables before Int32.TryParse
gets executed:
EDIT #2: Exception StackTrace:
at ...Presenter.GenerateClipName()
at ...Presenter.Cancel()
at ...View.CancelButton_Click(object sender, System.Windows.RoutedEventArgs e)
The stack trace doesn't include the Int32.TryParse
method, which is wondering me somehow.