I have created following table from DynamoDB service in Amazon Web Services:
which I want to display on an ASP.NET application. The problem is that it returns a NullReferenceException, and I can't event debug it. I have created a ViewModel as follows:
public class DynamoDB
{
public int userNO { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
}
and an extra class to access the DynamoDB table from AWS:
public class DynamoContext
{
Credentials.Credentials credentials = new Credentials.Credentials();
public IEnumerable<DynamoDB> GetProducts()
{
IEnumerable<DynamoDB> products = null;
RegionEndpoint region = RegionEndpoint.GetBySystemName("eu-central-1");
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials.AccessKey, credentials.SecretAccessKey, region);
DynamoDBContext context = new DynamoDBContext(client);
products = context.Scan<DynamoDB>();
return products;
}
}
and a controller which has to access this IEnumerable and convert it to a List of objects.
public class DynamoController : Controller
{
//
DynamoContext dc = new DynamoContext();
[HttpGet]
public ActionResult Index()
{
List<DynamoDB> objList = dc.GetProducts().ToList();
return View("users", objList);
}
}
and finally my View which has to display the table on the Index page:
@{
ViewBag.Title = "Home Page";
}
@model List<FinalApplication.Models.DynamoDB>
<div class="jumbotron">
<h1>Home Monitoring Application</h1>
</div>
<table>
@foreach (FinalApplication.Models.DynamoDB objUser in Model)
{
<tr>
<td>@objUser.userNO.ToString()</td>
<td>@objUser.firstName</td>
<td>@objUser.lastName</td>
</tr>
}
</table>
When running the application in Google Chrome, it returns following exception:
I have even set some breakpoints in the DynamoContext class, to check whether it gets any data from AWS, but the Exception occurs even before they are triggered. How can I check where the issue is ?.