Http.GetAsync (URI); The message "The parameter is incorrect".
Following the example of my video on Channel 9 Developing Universal Windows Apps with C # and XAML: (05) Create a Service "for" Create a Service "I managed to get it back online in March 2015, have made a lot of additions to my project since then and the system and now I will return to the continuation of this part of my project.
Running in debug mode doesn't give me a specific reason why it fails other than:
- e {Windows.UI.Xaml.UnhandledExceptionEventArgs} Windows.UI.Xaml.UnhandledExceptionEventArgs
- Exception {"The parameter is incorrect.\r\n\r\nThe parameter is incorrect.\r\n"} System.Exception {System.ArgumentException}
+ [System.ArgumentException] {"The parameter is incorrect.\r\n\r\nThe parameter is incorrect.\r\n"} System.ArgumentException
- Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
+ [System.Collections.ListDictionaryInternal] {System.Collections.ListDictionaryInternal} System.Collections.ListDictionaryInternal
IsFixedSize false bool
IsReadOnly false bool
+ Keys {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
+ Values {System.Collections.ListDictionaryInternal.NodeKeyValueCollection} System.Collections.ICollection {System.Collections.ListDictionaryInternal.NodeKeyValueCollection}
- Results View Expanding the Results View will enumerate the IEnumerable
- [0] {System.Collections.DictionaryEntry} object {System.Collections.DictionaryEntry}
Key "RestrictedDescription" object {string}
Value "The parameter is incorrect.\r\n" object {string}
+ Non-Public members
- [1] {System.Collections.DictionaryEntry} object {System.Collections.DictionaryEntry}
Key "RestrictedErrorReference" object {string}
Value null object
+ Non-Public members
- [2] {System.Collections.DictionaryEntry} object {System.Collections.DictionaryEntry}
Key "RestrictedCapabilitySid" object {string}
Value null object
+ Non-Public members
- [3] {System.Collections.DictionaryEntry} object {System.Collections.DictionaryEntry}
Key "__RestrictedErrorObject" object {string}
- Value {System.Exception.__RestrictedErrorObject} object {System.Exception.__RestrictedErrorObject}
- RealErrorObject COM Object object {System.__ComObject}
+ base COM Object System.MarshalByRefObject {System.__ComObject}
+ Non-Public members
+ Interface View
- Dynamic View Expanding the Dynamic View will get the dynamic members for the object
Empty "No further information on this object could be discovered" string
+ Non-Public members
+ Non-Public members
- [4] {System.Collections.DictionaryEntry} object {System.Collections.DictionaryEntry}
Key "__HasRestrictedLanguageErrorObject" object {string}
Value false object {bool}
+ Non-Public members
HelpLink null string
HResult -2147024809 int
+ InnerException null System.Exception
Message "The parameter is incorrect.\r\n\r\nThe parameter is incorrect.\r\n" string
Source "" string
StackTrace null string
TargetSite null System.Reflection.MethodBase
+ Static members
+ Non-Public members
Handled false bool
Message "The parameter is incorrect.\r\n" string
I have read and applied this " Error message: parameter is invalid " resolution on Microsoft support site with no success. Since I have multiple language packs installed but the default is set to "English" so I can't see how this causes a failure.
My MainPageViewModel that handles OnNavigatedTo and http.GetAsync (uri):
public async System.Threading.Tasks.Task<T> GetAsync<T>(Uri uri)
{
using (var http = new Windows.Web.Http.HttpClient())
{
http.DefaultRequestHeaders.Add("Accept", "application/json");
var response = await http.GetAsync(uri);
if (response.StatusCode != Windows.Web.Http.HttpStatusCode.Ok)
throw new Exception(response.StatusCode.ToString());
string json = await response.Content.ReadAsStringAsync();
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
}
}
public async override void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary<string, object> viewModelState)
{
try
{
var service = System.IO.Path.Combine(this._settings.WebApiBase, Parameters.TSUser);
var tsuser = await GetAsync<IEnumerable<NathsarTS.DataModels.Models.TSUser>>(new Uri(service));
other parts of the project that make up the fields above:
public class Settings : ISettings
{
public Settings()
{
WebApiBase = "http://localhost:58317/api/";
...
}
public static class Parameters
{
public const string TSUser = "TSUsers";
...
}
public class TSUsersController : ApiController
{
private NathsarTSEntities db = new NathsarTSEntities();
// GET: api/TSUsers
public IQueryable<TSUser> GetTSUsers()
{
return db.TSUsers;
}
...
}
The exception message after running it:
The value does not fall within the expected range.
What else do I need to check to get this working?
Additional research:
After building a basic app with WebApi (2014 SQLExpress Edmx) and PCL (for my generic table classes) I found something like a bazaar when doing http.GetAsync (uri), I get ListBox related Exception I am using:
- ) I am implementing Window Phone Pivot which I got from Window Dev Center project for My Windows App Universal Solution. XAML FlipView Sample Control
- This project uses SeletedItem to bind to FlipView, in which case it does not throw an exception when executing http.GetAsync (uri),
- however, when I use SelectedIndex I get an Exception.
- the reason for using http.GetAsync (uri) is to fetch items for ListBox from SQLExpress 2014 database and for some reason it throws this exception.
Current solution:
My acceptable job was to remove the binding from the XAML and create it in code:
var service = System.IO.Path.Combine("http://localhost:53397/api/", "TSPivotMenus");
var tspivotmenus = await GetAsync<IEnumerable<TSPivotMenu>>(new Uri(service));
this.TSMainMenu.ItemsSource = tspivotmenus;
Binding binding = new Binding
{
Path = new PropertyPath("SelectedIndex"),
Mode = BindingMode.TwoWay,
ElementName = this.TSMainFlipView.Name
};
this.TSMainMenu.SetBinding(ListBox.SelectedIndexProperty, binding);
But it would be great to find out why this is happening!
My conclusion:
After further research and meditation, the only thing I can figure out why this exception is being thrown is when the ListBox has no items to select, or by default, while waiting for an async method so I can fill it with items.
So http.GetAsync (uri) doesn't actually raise the Exception directly, but in-direct because I need the data from it for the ListBox .
If anyone has time to check and confirm this, I can mark it as Answered .
source to share
No one has answered this question yet
Check out similar questions: