Windows 8 – Value does not fall within the expected range.

In Windows 8 Application development, we came across the “Value does not fall within the expected range.” exception in two scinarios.

Scenario 1: We have a CollectionViewSource defined in our XAML called sampleData

<CollectionViewSource x:name=”sampleData” />

The source of the CollectionViewSource is set using the following code

sampleData.Source=Utility.GetData(custId);

where we are getting the data from an asynchronous method, GetData in the Utility class.

public async static Task<List<Data>> GetData(string data)

{

………………………………

……………………………….

……………………………….

}

Solution:

Call the asynchronous method using await

sampleData.Source=await Utility.GetData(custId);

Scenario 2: Another scenario, where we used the following code

<CollectionViewSource x:name=”sampleData” />

 

sampleData.Source=await Utility.GetData(custId);

 

public async static Task<Data> GetData(string data)

{……………………………………………………………………….}

Solution:

CollectionViewSource requires a collection data source. In our sample, it returns an object of type Data.

public async static Task<List<Data>> GetData(string data)

{……………………………………………………………………….}

Advertisements

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in Windows, Windows 8 App and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s