title: Creation of Dynamic Entities in MS CRM 4.0
body: <p>I am trying to create a new contact using Dynamic Entity. The sample i found in CRM SDK had this code.</p>
  
  <pre><code>// Set the properties of the contact using property objects.
          StringProperty firstname = new StringProperty();
          firstname.Name = "firstname";
          firstname.Value = "Jesper";
          StringProperty lastname = new StringProperty();
          lastname.Name = "lastname";
          lastname.Value = "Aaberg";
  
          // Create the DynamicEntity object.
          DynamicEntity contactEntity = new DynamicEntity();
  
          // Set the name of the entity type.
          contactEntity.Name = EntityName.contact.ToString();
  
          // Set the properties of the contact.
          contactEntity.Properties = new Property[] {firstname, lastname};
  </code></pre>
  
  <p>In my code i have the following implementation.</p>
  
  <pre><code>        StringProperty sp_Field1 = new StringProperty("Field1","Value1");
          StringProperty sp_Field2 = new StringProperty("Field2","Value1");
  
          CrmService service = new CrmService();
          service.Credentials = System.Net.CredentialCache.DefaultCredentials;
          // Create the DynamicEntity object.
          DynamicEntity contactEntity = new DynamicEntity();
          // Set the name of the entity type.
          contactEntity.Name = EntityName.contact.ToString();
          // Set the properties of the contact.
          contactEntity.Properties = new Property[] {sp_Field1,sp_Field2};
  </code></pre>
  
  <p>I don't see much differences in the code. In the examples i found in the internet i have the same implementation as i found in SDK. But if i run the same i get the following error</p>
  
  <blockquote>
    <p>CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.StringProperty' to 'Microsoft.Crm.Sdk.PropertyCollection'</p>
  </blockquote>
  
  <p>I tried created a new variable of type PropertyCollection(one that belongs in mscrm namespace) and added the stringpropertys into that and passed it to the entity. </p>
  
  <pre><code>Microsoft.Crm.Sdk.PropertyCollection propTest = new Microsoft.Crm.Sdk.PropertyCollection();
          propTest.Add(sp_SSNNo);
          propTest.Add(sp_FirstName);
          contactEntity.Properties = new Property[] {propTest};
  </code></pre>
  
  <p>This gave me the following error</p>
  
  <blockquote>
    <p>CS0029: Cannot implicitly convert type 'Microsoft.Crm.Sdk.PropertyCollection' to 'Microsoft.Crm.Sdk.Property'</p>
  </blockquote>
  
  <p>I am sure its a minor typecasting error but i am not able to figure out where the error is. And moreover, even if it was a typecasting error why is it working for all the samples given in the internet and not for me. I tried getting the code sample to run but i am encountering the same conversion error. Please let me know if you need more info on this, any help on this would be appreciated.</p>