UnitsNet icon indicating copy to clipboard operation
UnitsNet copied to clipboard

Default(Temperature).Degreescelcius thows NotImplemented exception. Its not clear accessing a default value instance

Open brianro opened this issue 4 months ago • 6 comments

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):

  1. 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)

brianro avatar Aug 20 '25 19:08 brianro

I'll defer this to @josesimoes who authored and maintains the NanoFramework version of UnitsNet.

angularsen avatar Sep 19 '25 19:09 angularsen

Never seen something similar... Will have to try and reproduce it. Please hold.

josesimoes avatar Sep 20 '25 18:09 josesimoes

Just tested this on a .NET 9 console app and the behaviour is the same. Nothing specific with nanoFramework execution.

Image

I would say this is not the intended usage, or something missing in the default constructor?

josesimoes avatar Sep 23 '25 08:09 josesimoes

@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.

brianro avatar Oct 22 '25 20:10 brianro

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.

github-actions[bot] avatar Nov 22 '25 02:11 github-actions[bot]

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.

angularsen avatar Nov 23 '25 10:11 angularsen