✅ Item Returning Null From View Model??? Avalonia
MainWindowViewModel: https://pastebin.com/v5A0u9VJ
TermsOfServiceViewModel: https://pastebin.com/BQx4qd1D
I'm not understanding why when I click the run button to debug and run the program, that's when it deciedes to tell me that the model inside of the MainWindowViewModel's TermsOfService method cannot be null?
94 Replies
what's the full error? with line numbers etc
this is all it gives me but it's not until after I click the run button
one of those methods has a parameter named
source
that you're passing null to when you shouldn't
(SetupModel)null
looks suspect to me
and the reason it's "deciding" to tell you it's null at runtime is because it's a runtime error, not a compiler error
it looks like you probably have compile time suggestions/hints about nullability, did you look at those?I don't know what those are or what they look like. apologies
ok so getting ride of the
.Select(_ => (SetupModel)nul))
like fixed it. Thanks for your helpthe green squiggles
you should do yourself a favor and add
<WarningsAsErrors>Nullable<WarningsAsErrors>
to your .csproj properties
then code that has sketchy nullability won't compile in the first placewhere does it go in the csproj file?
got it
that's making everything error.
every json serialization and it's usage beneath it is now an error
then you have a lot of sketchy nullability
as in, things that could be null that your code doesn't check for
yes
deserializing json may return null, but your code doesn't check for it
they're all the same respectively
so how do I fix it?
which is a potential runtime crash
by adding null checks
ok I'll go research that
so googling this, I found https://www.thomasclaudiushuber.com/2020/03/12/c-different-ways-to-check-for-null/ is that what you're talking about?
Thomas Claudius Huber
Thomas Claudius Huber
C#: Different ways to Check for Null
What is the classic way to check if for example a parameter value is null? If you've developed with C# since a while, you might be familiar with this classic syntax: public static int CountNumberOfSInName(string name) { if (name == null) { throw new ArgumentNullException(nameof(name));…
if yes, then that means I need to build some type of universal error and exception handler