-4
string fc = .......
Dictionary<string, string> fcData = serializer.Deserialize<Dictionary<string, string>>(fc);


if (!string.IsNullOrWhiteSpace(fcData["Diploma.GraduationBeginDate"]))
  DateTime? GraduationBeginDate = Convert.ToDateTime(fcData["Diploma.GraduationBeginDate"]);

Error : {"Object reference not set to an instance of an object."}

This is my code . fcData has value, count =11 and fcData["Diploma.GraduationBeginDate"] value is 10.05.2016 why it doesn't work ? Could you help me ?

  • 5
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Gilad Green Jun 28 '16 at 13:15
  • Nope , i couldnt find. – Osman Yalçın Jun 28 '16 at 13:25
  • 1
    Please post a more complete section of your code without `.......`. Also - when you debug the code and go line my line on what line does it throw the exception? – Gilad Green Jun 28 '16 at 13:28
  • 1
    At which line does the exception occur? – Martin Mulder Jun 28 '16 at 13:33
  • One of your objects doesn't have a value. Debug the code and find which line throws the exception. Then hover your mouse over each object in that statement looking for a `null` value. If `fcData` has a value I suspect you're getting the exception at the `Deserialize` statement? Possibly your `serializer` hasn't been initialized. Without seeing your full code we can only guess. Please read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and the linked [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Tone Jun 28 '16 at 16:51
  • Thank you for information . I solved the problem . "GraduationBeginDate" is actually "diploma.GraduationBeginDate" this is my mistake.By the way diploma is object.The problem is Before set , i didn't take instance . thanks again for your help. – Osman Yalçın Jun 29 '16 at 07:21

1 Answers1

2

You can affect DateTime to DateTime? :

DateTime t1 = someDate;
DateTime? t2;
t2 = t1; <- it works

in contrary :

DateTime? t1 = someDate;
DateTime t2;
t2 = t1; <- won't work, you need to cast it
t2 = (DateTime)t1;

Hope this will help.

awassif
  • 21
  • 3
  • Thank you for information . I solved the problem . "GraduationBeginDate" is actually "diploma.GraduationBeginDate" this is my mistake.By the way diploma is object.The problem is Before set , i didn't take instance . thanks again for your help. – Osman Yalçın Jun 29 '16 at 07:22