title: CRM 2013: Using the value of an Option Set input parameter in a custom workflow activity
body: <p>I was trying to use an optionset input parameter in custom workflow activity, so I have used the below code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  
  using System.Activities;
  using Microsoft.Xrm.Sdk;
  using Microsoft.Xrm.Sdk.Workflow;
  using Microsoft.Xrm.Sdk.Query;
  using System.Globalization;
  
  namespace ITWorx.VisitManagement.Workflows
  {
      public class FormatDate : CodeActivity
      {
          [Input("Preferred Language")]
          [AttributeTarget("contact", "itworx_preferredlanguage")]
          [Default("894330000")]
          public InArgument&lt;OptionSetValue&gt; PreferredLanguage { get; set; }
  
          protected override void Execute(CodeActivityContext context)
          {
              IWorkflowContext workflowContext = context.GetExtension&lt;IWorkflowContext&gt;();
              IOrganizationServiceFactory serviceFactory = context.GetExtension&lt;IOrganizationServiceFactory&gt;();
              IOrganizationService service = serviceFactory.CreateOrganizationService(workflowContext.UserId);
  
              int preferredLanguage = PreferredLanguage.Get&lt;OptionSetValue&gt;(context).Value;
  
          }
      }
  }
  </code></pre>
  
  <p>But an exception is thrown in the below line:</p>
  
  <pre><code>int preferredLanguage = PreferredLanguage.Get&lt;OptionSetValue&gt;(context).Value;
  </code></pre>
  
  <p>Exception:
  NullReferenceException
  {"Object reference not set to an instance of an object."}</p>
  
  <p>Please advise</p>