The value cannot be null. Parameter name: source

Source: Internet
Author: User

Today the debugger always reports an exception:

The value cannot be null.
Parameter name: Source

Exception Details: System.ArgumentNullException: The value cannot be null.
Parameter name: source

The breakpoint was found to be this code error, the exception that occurs is usually a parameter in the method is empty, and my method does not have a parameter named source Ah, and later found that processors is NULL, the call to the Select method will of course error.

processors = taskwfservice.identifynextworkflowprocessors (Currentuserid, currenttaskworkflow.reporttaskid); var Processors New taskworkflowprocessor {Processor = Item}). ToList ();

But according to our usual experience, a null object, when calling its method, should throw NullReferenceException An instance exception that does not set the object to an object ? For example, we call the ToString () method

var // thrown a NullReferenceException

In fact, that's the problem. In the Select () method, press F12 on the Select to view the definition

 Public Static Ienumerable<tresult> Select<tsource, tresult> (Thissource, Func<tsource, TResult > selector);

This is a System.Linq extension method (not before. NET 3.5), except for Select there are many common, such as Where, any, by, SelectMany, take, etc.

This method internally determines that the passed-in parameter, source null, throws a ArgumentNullException.

I think if the this parameter in the extension method is NULL, is it more appropriate to throw a NullReferenceException? At least it's easier to get rid of mistakes.

The value cannot be null. Parameter name: source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.