title: Convert List<Employee> to Byte [] array
body: <p>I have List of Employee Objects to Convert to Byte [] array...</p>
  
  <p>I used Following Code to conversion:</p>
  
  <pre><code> private byte[] ObjectToByteArray(List&lt;Employee&gt; obj)
          {
              if (obj == null)
                  return null;
              var bf = new BinaryFormatter();
              var ms = new MemoryStream();
              bf.Serialize(ms, obj);
              return ms.ToArray();
          }
  </code></pre>
  
  <p>But it gives me following error..</p>
  
  <pre><code> at System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
     at System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
     at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
     at System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
     at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
     at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
     at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
     at ExportToExcel.Controllers.HomeController.ObjectToByteArray(List`1 obj) in C:\Users\mutturajnb\Documents\Visual Studio 2010\Projects\ExportToExcel\ExportToExcel\Controllers\HomeController.cs:line 46
     at ExportToExcel.Controllers.HomeController.Index() in C:\Users\mutturajnb\Documents\Visual Studio 2010\Projects\ExportToExcel\ExportToExcel\Controllers\HomeController.cs:line 26
     at lambda_method(Closure , ControllerBase , Object[] )
     at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
     at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
     at System.Web.Mvc.ControllerActionInvoker.&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12()
     at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  </code></pre>
  
  <p>Do I need to decorate my class members with  <code>SerializableAttribute</code> ?</p>