More in this section

Forums / Developing with Sitefinity / getmetadata not working for events

getmetadata not working for events

2 posts, 0 answered
  1. Priya Ramesh
    Priya Ramesh avatar
    26 posts
    23 Jul 2009
    01 Oct 2009
    Link to this post

      The following code was working fine.I added a custom field to Events module. Now I am getting an error when I use getmetadata. also another thing I did was set Title's localizable to true.



    EventsManager manager = new EventsManager("Events");



    IContent ieve = manager.Content.GetContent(new Guid(sEventId));


    sSubject = ieve.GetMetaData(



    it says

    Object reference not set to an instance of an object.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 41:         if (ieve != null)
    Line 42:         {
    Line 43: sSubject = ieve.GetMetaData("Title").ToString();Line 44: 
    Line 45:             //sCity = ieve.GetMetaData("City").ToString();

    Source File: c:\Projects\EU Website\Handlers\EventHandler.ashx    Line: 43

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       EventHandler.ProcessRequest(HttpContext context) in c:\Projects\EU Website\Handlers\EventHandler.ashx:43
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    12 Sep 2017
    01 Oct 2009
    Link to this post
    Hi Priya Ramesh,

    Please take a look at the sample below:

    Guid sEventId = new Guid("884895D7-8E83-43C5-A9C9-1F788D7B09D3"); 
    EventsManager manager = new EventsManager("Events"); 
    IContent ieve = manager.Content.GetContent(sEventId); 
    string sSubject = (string)ieve.GetMetaData("Title"); 

    One of the parameters you pass is returning null value and this is why you get object reference error. You could also attach the code to Visual Studio debugger and see which is the problematic object or parameter.

    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered