|
I'm not an expert or even a novice ...
(serious)
Can't you just "unLINQ" this and find and fix the error and LINQ it up again ?
I'd rather be phishing!
|
|
|
|
|
Yes. But that's my point. To get a reasonable error message out of LINQ the solution is do it without LINQ. meh.
Real programmers use butterflies
|
|
|
|
|
It's not really LINQ's fault, it's the chaining of multiple commands into a single statement and also a little of your own inexperience; given that error message many would know exactly where to look.
|
|
|
|
|
A couple of possibly interesting bits of feedback, assuming that code comes from here:
- Adding it to a WinForms app created with .NET Core 3.1 or .NET 5 and turning on nullable reference types finds 17 potential accidental nulls in the code from that SO post. But the Columns.AddRange call itself isn't one of them because WinForms wasn't built with NRT enabled. So the compiler decides it can't say one way or another if passing a null values argument to AddRange is okay.
- Resharper catches the potential error whether you're using .NET Core/.NET 5 or .NET Framework. It even suggests a fix. The static analysis it's doing must look at AddRange and notice that the first thing that method does is throw an exception if values is null.
|
|
|
|
|
Ryan Peden wrote: Resharper catches the potential error
Ryan Peden wrote: It even suggests a fix.
|
|
|
|
|
Sounds like nullable reference types is reason enough in itself to upgrade to .Net 5.
|
|
|
|
|
Ryan Peden wrote: The static analysis it's doing must look at AddRange and notice that the first thing that method does is throw an exception if values is null.
I suspect it's more likely that it has "external annotations" for the type in question.
External Annotations—ReSharper[^]
R# is already slow enough; if it had to do static analysis on every framework method you called, it would be completely unusable.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That certainly makes using LINQ a bit nicer.
Real programmers use butterflies
|
|
|
|
|
The main challenge of LINQ that you don't like (I believe) is one that is quite difficult to accept (for me too) and for many of us who originally learned imperative programming.
The main challenge is that LINQ is a declarative construct within an imperative programming language.
You probably know this already.
Declarative languages expect you to tell them what you want (not how they should do it).
However, how they actually get you want you want is hidden (black box).
So when they fail, it is quite difficult to know where / why they failed.
With imperative programming you have written the steps to get the thing to do the thing and you know where the problem is.
Squirrel From A Different Dimension
This may not help but it'll help you understand that even though the animal you are wrestling with looks very much like a normal squirrel, it is actually a squirrel that lives in another dimension and it behaves quite differently.
|
|
|
|
|
p.GetCustomAttributes(true).OfType<DisplayNameAttribute>()
I believe OfType<>() is returning a null.
honey the codewitch wrote: The LINQ isn't really that bad here.
Actually, it's rather horrific. Not to mention what looks like completely unnecessary and probably wrong FirstOrDefault() usage, the reflection usage which looks like it could be simplified, and other confusing things. And the probably useless ToArray().
honey the codewitch wrote: even though I didn't write it
Whew!
|
|
|
|
|
Marc Clifton wrote: I believe OfType<>() is returning a null.
Nope.
OfType<T> will throw an exception if the input sequence is null . If the input sequence is empty, or doesn't contain any matching elements, it will return an empty sequence. It can never return null .
Also, the elements within the returned sequence will never be null .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is illustrative of the point of my OP. If the error was clearer there would have been no confusion here.
Real programmers use butterflies
|
|
|
|
|
Yet another example of the school of thought that replacing if , for , and while by declarative constructs results in code that is simplicity itself to read, robust, and completely error free.
In a pig's eye.
Software Zen: delete this;
|
|
|
|
|
Exception that leaves you clueless.. yes, it happens :/
The null reference exception is a big culprit with those.. :/
However, I dare say that (perhaps) Stacktrace could help provide a bit more helpful insight here?!
|
|
|
|
|
I mean, yes. eventually. but it (as someone mentioned earlier but I forget who) reminds me of C++ template exceptions. The code and the exception couldn't seem more unrelated on the surface, and code that isn't communicative at face value is problematic, which is basically my point here.
I have the same complaint about C++ templates and generic programming despite being in love with GP. I guess for me the power of GP outweighs the incomprehensibility of it but I just don't feel that way with LINQ.
Real programmers use butterflies
|
|
|
|
|
Try taking a look at the stack trace from an async method (prior to .NET Core 2.1).
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, those were always fun. Sometimes - when the code flow was complicated - I used to prototype using blocking calls just so I could debug the logic, and then slowly roll in the asynchronous methods (BeginWrite, etc) until it stopped working.
Real programmers use butterflies
|
|
|
|
|
is that custom generated? because if you had to write that -"their's your sign"
Charlie Gilley
<italic>Stuck in a dysfunctional matrix from which I must escape...
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
modified 16-Feb-21 22:47pm.
|
|
|
|
|
Is the Dentist of the Year award just a little plaque?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Their crowning achievement?
|
|
|
|
|
they had to root around in the canal to find it.
To err is human to really elephant it up you need a computer
|
|
|
|
|
Producing the awards ceremony requires a lot of drill.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Yeah, they really had to get their teeth into it.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I wonder if all the cavity searches were worth it.
|
|
|
|
|
That award, mentioned in your post, caries a lot of weight. Hopefully, others won't think it a tongue-in-cheek remark. I wonder if those who didn't receive the award have a feeling of floss? How does one extract that information, unless they have some special pull?
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|