在关注第9频道" Developing Universal Windows Apps with C# and XAML: (05) Building a service"为"建立服务"我能够在2015年3月恢复工作,从那以后我的项目和系统增加了很多,现在又回到了我项目的这一部分。
在调试中运行它并没有给我一个特定的原因,为什么它失败了除了:
- 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
我阅读并应用了此决议" Error Message: The Parameter Is Incorrect"在Microsoft支持网站上没有成功。因为我确实安装了多个语言包,但默认设置为英语,所以我不知道这是如何导致失败的。
我的MainPageViewModel处理OnNavigatedTo和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));
构成上述字段的项目的其他部分:
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;
}
...
}
让它运行后的异常消息的消息是:
价值不在预期范围内。
我需要检查什么才能完成这项工作?
其他研究:
使用WebApi(2014 SQLExpress Edmx东西)和PCL(对于我的共享Table类)创建基本应用程序后,我在执行http.GetAsync(uri)时发现了一些相当于集市的内容我得到了一个与之相关的异常列表框我使用:
当前解决方案:
我可接受的解决方法是从XAML中删除Binding并在代码中创建它:
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);
但是,找出这种情况发生的原因会很棒!
我的结论:
经过进一步的研究和冥想后,我唯一可以看到为什么会出现这种异常的原因是 ListBox 在等待< ListBox 时没有要选择或默认的项目em> async 方法完成,所以我可以用项填充它。
所以 http.GetAsync (uri)实际上并没有直接导致例外 ,而是直接因为我需要来自它的数据用于<strong> ListBox 。
如果有人有空闲时间进行测试并确认,我可以将其标记为已回答。