Tuesday, 15 January 2013

Server Error - Value Cannot Be Null - C# set; -



Server Error - Value Cannot Be Null - C# set; -

i still new c# , have been fine declaring {get; set;}, per solution here needed manual get , run error says value cannot null, after trying "filter by" on page here.

the error points here in debugger, due me not having set.

public string employeenamesstring { { homecoming string.join(", ", this.employeenames); } //system.argumentnullexception }

i assume should seek set { this.employeenames = (somevalue); } not sure set as..

could explain me why occuring, , how may remedy this?

thank you!

viewmodel

public class starringviewmodel { public int movieid { get; set; } public int roleid { get; set; } public int employeeid { get; set; } public string moviename { get; set; } public string moviedescription { get; set; } public datetime? moviereleasedate { get; set; } public string role { get; set; } public string employeename { get; set; } public datetime employeebirthdate { get; set; } public ienumerable<string> employeenames { get; set; } public string employeenamesstring { { homecoming string.join(", ", this.employeenames); } set { this.employeenames = somevalue; } //attempt } }

initially, employeenames collection going null, phone call string.join throw argumentnullexception if collection has not been initialized.

public ienumerable<string> employeenames { get; set; } public string employeenamesstring { { homecoming string.join(", ", this.employeenames); } }

one possibility initialize employeenames in constructor, it's not null when access employeenamesstring. may want create setter private, nil outside class can create employeenames null either.

public class starringviewmodel { public starringviewmodel { employeenames = new list<string>(); } ... ... public ienumerable<string> employeenames { get; private set; } public string employeenamesstring { { homecoming string.join(", ", employeenames); } } }

c#

No comments:

Post a Comment