Default(Temperature).Degreescelcius thows NotImplemented exception. Its not clear accessing a default value instance
Describe the bug
.NetNano, accessing DegreesCelcuis of a Default(Temperature) throws NotImplemented Exception.
An unhandled exception of type 'System.NotImplementedException' occurred in UnitsNet.Temperature.dll Additional information: Can not convert 0 to base units.
To Reproduce Steps to reproduce the behavior (just an example):
- Create .NetNano project and add UnitsNet.
Execute this code
var x = default(Temperature); Debug.WriteLine($"{x.DegreesCelsius}");
Behavior
Throws
An unhandled exception of type 'System.NotImplementedException' occurred in UnitsNet.Temperature.dll Additional information: Can not convert 0 to base units.
Expected behavior
I understand this is a design decision: It wasn't clear that the value is actually a default(Temperature)
If you look at the additional context below, you can see how I bumped into it and the problem that created it.
Maybe a clearer message that the value is a default or unassigned. Does it need an "IsValid" or "IsAssigned" member? Something about "No value assigned to Temperature". Should there be a Temperature.Default member?
Additional context
I found this because another clause assigned its property to default(Temperature) which I stored and tried to access later, resulting in this error.
It just not easy to see or detect that the class is a default(Temperature) and not an actually assigned valid value)
I'll defer this to @josesimoes who authored and maintains the NanoFramework version of UnitsNet.
Never seen something similar... Will have to try and reproduce it. Please hold.
Just tested this on a .NET 9 console app and the behaviour is the same. Nothing specific with nanoFramework execution.
I would say this is not the intended usage, or something missing in the default constructor?
@josesimoes I believe this is an issue with the unitsNet library not handling values of zero correctly? e.g. 0C != 0F and I don't think the library is handling zero properly. @angularsen ? Calling attention back to this issue please.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
default(Temperature).DegreesCelsius works in UnitsNet 6.0.0-pre17 and 5.75.0.
Sounds like this is specific to the nanoFramework code generator, which differs a lot from the main library. I unfortunately am swamped with work these days and don't have much time, but pull requests are welcome and I'll help get it merged.