Click here to Skip to main content
16,019,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI guys,
Im getting the Error at when we are declaring object for the LIST.ERROR is like below.


Nullable object must have a value. Error Source: mscorlib Error Inner Exception: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)

My code is :

public IList<entity> PrepareEntity(Item item, Inventory inventory)
{
IList<entity> objItems = new List<entity>();-------------ERROR at this line.

Please suggest me



Thanks in advance,
Pavan G.

What I have tried:

Nullable object must have a value. Error Source: mscorlib Error Inner Exception: at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
Posted
Comments
Ehsan Sajjad 15-Feb-18 8:11am    
can you show the Entity class implementation, it could be something in it.
Shashank Laxman 15-Feb-18 8:31am    
https://social.msdn.microsoft.com/Forums/vstudio/en-US/4377b2dd-fdf6-42f7-baa8-d900430d9454/c-list-vs-ilist?forum=csharpgeneral
Richard Deeming 15-Feb-18 10:58am    
That exception is not being thrown by the line you have shown. It's being thrown when you try to access the Value property of a Nullable<T> type which does not have a value.
Member 12057131 16-Feb-18 6:30am    
Hi All,

@Richard : But that is just object creation right.then y do i get that error.

@Ehsan : Entity class has some properties.like Name,SkU,Weight and it has Serialiazable Attribute.that entity has taken to another project by give the reference.
then i created the object like that .i.e.,
IList<entity> objItems = new List<entity>();

i passed the data to that properties of Entity.after then i added all the data to ILIST entity.
Maciej Los 20-Feb-18 16:44pm    
Use [Reply] widget to be sure that member will be notified about your reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900