I am trying to store a user into my Azure Table but when trying to create a user I'm getting "object not set to an instance of an object", why???
UserEntity entry = new UserEntity();
entry.UserName = pUserName;
entry.MiniatureImageURL = blob.Uri.ToString();
entry.PhotosUrl.Add(blob.Uri.ToString()); //THIS IS A LIST of strings
Connection cn = new Connection();
cn.AddUserEntries(entry);
My connection class is defined as follows:
Here I'm trying to add the new user to the current context and then try to save the item in the storage:
public void AddUserEntries(UserEntity newItem)
{
try
{
this.context.AddObject("UserEntity", newItem);
this.context.SaveChanges();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
static Connection()
{
try
{
storageAccount = CloudStorageAccount.FromConfigurationSetting("dataconnectionstring");
CloudTableClient.CreateTablesFromModel(
typeof(Connection),
storageAccount.TableEndpoint.AbsoluteUri,
storageAccount.Credentials);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public Connection()
{
try
{
this.context = new UserDataContext(storageAccount.TableEndpoint.AbsoluteUri, storageAccount.Credentials);
this.context.RetryPolicy = RetryPolicies.Retry(3, TimeSpan.FromSeconds(1));
}
catch (Exception ex)
{
throw new Exception("There was a problem trying to create the user. " + ex.Message);
}
}