I have an “Id” dependency property declared:
public long Id
{
get { return (long)GetValue(IdProperty); }
set { SetValue(IdProperty, value); }
}
public static readonly DependencyProperty IdProperty =
DependencyProperty.Register("Id", typeof(long),
typeof(Component), new PropertyMetadata(-1));
“Component” is a User Control that have “Id”.
When I run the application it gives me an exeption:
An unhandled exception of type ‘System.TypeInitializationException’ occurred in PresentationCore.dll
Additional information: The type initializer for ‘My_Program.Component’ threw an exception.
If i change the type “long” to “int” everything works fine.
What is the problem? can’t I create a dependency property of type “long”?
Thank you for your help.
Try casting the default value to long: