This is the method i am using.
try
{
List<Patient> pList = await App.MobileService.GetTable<Patient>().Where(
patient => patient.id == 1).ToListAsync();
foreach (Patient p in pList)
{
System.Diagnostics.Debug.WriteLine("{0}, {1}", p.id, p.first_name);
}
}
catch (Exception err)
{
System.Diagnostics.Debug.WriteLine("ERROR! : {0}", err.Message);
}
Here's the Patient entity.
class Patient
{
public int id { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string middle_name { get; set; }
public string nirc { get; set; }
public int bed_id { get; set; }
}
Here's the error i am getting.
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in Microsoft.Azure.Zumo.WindowsPhone8.Managed.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
When i wrap my method within a TryCatch, i get this message
Error : The request could not be completed. ()
Here's the stack error message
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.CreateMobileServiceException(String errorMessage, IServiceFilterRequest request, IServiceFilterResponse response)
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, JToken body)
at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<RequestAsync>d__f.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<SendReadAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<EvaluateQueryAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery`1.<ToListAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at PhoneApp1.MainPage.<populate>d__0.MoveNext()
A few points to note.
Permission is set to Anybody with the Application Key
I've added reference to Windows Azure Mobile Services Managed Client
I've already inserted this code within App.XAML.CS. using Microsoft.WindowsAzure.MobileServices;
I've already placed this piece of code acquired from this website within App.XAML.CS.
public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );
Why am i unable to connect to my database? I've tried running these codes on a Windows Store Application and it worked. Previously i've done the exact same thing and it worked as well.
This link saved me.
Apparently, all i had to do is to change the service address from https to http. So instead of this,
public static MobileServiceClient MobileService = new MobileServiceClient(
"https://www.example.azure-mobile.net/",
"fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa"
);
Change it to
public static MobileServiceClient MobileService = new MobileServiceClient(
"http://www.example.azure-mobile.net/",
"fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa"
);
Problem solved.
Check the date / time on your computer or the device. In my case I had powered on a dev phone that had been off for some time and the date / time was completely wrong. While changing the endpoint from HTTPS to HTTP does work around the issue, for me the proper solution was to keep HTTPS and fix the date / time on the device.
I solved this problem in my Android devices. You will need kill your app instance, change the system date/time to current and reopen the app.
Thanks Nathanial Woolls!!!
I can't comment because of my low reputation, I'm experiencing the same problem, but it's inconsistent.
If I try to use the registration page on my app that hits an Azure Mobile Service, sometimes it times out with the same error ("The request could not be completed. ()"), then if I try again immediately it works fine.
I'm using an actual Windows Phone Device and it's connected using Wi-Fi provided by my iPhone's hotspot which is actually 4G so there's definitely not a connection issue.
I read other articles that said there's no point trying to check if an internet connection is available, just try and send the data and deal with any issues. I deal with the issue but the issue shouldn't be happening.
Did you experience any more problems?
I've tried using https and http for the MobileService connection, doesn't seem to make any difference.
In case anyone else runs into this, I experienced the same issue when I simply had simply passed a URL with an incorrect subdomain to MobileServiceClient.
For instance, something like this:
public static MobileServiceClient MobileService = new MobileServiceClient(
"http://www.example.azure-mobile.net/",
"fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa"
);
Make sure that also this is turned off.
Related
XXXFunction is calling a function where the null reference failure is thrown with this line of code below:
await client.Groups[groupId].Members.References.Request().AddAsync(directoryObject);
The error is:
XXXFunction Failed due to System.NullReferenceException: Object reference not set to an instance of an object.
at XXXFunctionApp.XXX.Processors.XXXProcessor.<ProcessAsync>d__25.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at XXXFunctionApp.XXX.Functions.XXXFunction.<Run>d__3.MoveNext()
What is an effective way to handle this null reference? Are there instances where this could be thrown due to the GraphAPI unable to fetch the user due to long running processes, etc.?
I'm trying to implement a simple polling service that queries our TFS instance for build results (eventually this will be shown on a build monitor in the office). Following the examples here, I've come up with the following attempt:
var uri = new Uri("http://tfs:8080/tfs/defaultcollection");
var connection = new VssConnection(uri, new VssClientCredentials());
var client = connection.GetClient<BuildHttpClient>();
var builds = await client.GetBuildsAsync(
project: "OurProject",
maxBuildsPerDefinition: 1,
type: DefinitionType.Build);
but the last statement throws a NullReferenceException somewhere deep in the client library (full stack trace at the bottom).
I've tried the following, and it works, but of course it doesn't get me the information I'm looking for :)
var client = connection.GetClient<WorkItemTrackingHttpClient>();
var workItems = await client.GetWorkItemsAsync(ids: new List<int> { 7000, 7005});
Am I fundamentally misunderstanding something about how to query for builds? How do I avoid this exception?
Update: It's not just me!
I just discovered that this error isn't generated (only) on the client side; it's on the server side (too)! A GET request to the following url:
http://tfs:8080/tfs/defaultCollection/OurProject/_apis/build/builds?api-version=2.0&maxBuildsPerDefinition=1&type=build
yields a 500 Internal Server Error response with the following content:
{
"$id": "1",
"innerException": null,
"message": "Object reference not set to an instance of an object.",
"typeName": "System.NullReferenceException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"typeKey": "NullReferenceException",
"errorCode": 0,
"eventId": 0
}
Given this, how should I troubleshoot? What should I ask/tell the ops people who are running our TFS server? What are we looking for?
Stack trace for the (client-side) exception:
Unhandled Exception: System.AggregateException: One or more errors occurred.
---> Microsoft.VisualStudio.Services.WebApi.VssServiceResponseException: Object reference not set to an instance of an object.
---> System.NullReferenceException: Object reference not set to an instance of an object.
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.HandleResponse(HttpResponseMessage response)
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync>d__49.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__47`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.SendAsync>d__53`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Services.WebApi.VssHttpClientBase.<SendAsync>d__52`1.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at ConsoleApplication1.Program.Work() in c:\users\tly01\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 32
at ConsoleApplication1.Program.Main(String[] args) in c:\users\tly01\documents\visual studio 2015\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 20
I found the error. Short answer, RTFM :)
It turns out that the maxBuildsPerDefinition parameter is only valid if definitions is also specified. If only the former is given, the server returns 500.
(You could argue that 401 Bad Request would have been a better response, but at least now I know what to do about it.)
My workaround was to do the filtering on the client side instead; I get all builds of all projects, then group by definition and select the latest one:
var builds = await client
.GetBuildsAsync(
project: "OurProject",
type: DefinitionType.Build).Result
.GroupBy(build => build.Definition.Id)
.Select(g => g
.OrderByDescending(build.FinishTime ?? build.StartTime ?? DateTime.MinValue)
.First());
Context
I've written a parallel job framework in C# to import/export a large amount of data from/to an ElasticSearch cluster. To do this I've modelled each import or export of a single item as an object that gets executed at some point by the framework. To interface with ElasticSearch I'm using NEST (official .NET ElasticSearch client library) v1.7.1 and JSON.Net 7.0.1.
Each of the import/export task objects interacts with ElasticSearch using NEST. For performance reasons, I have written a proxy class which groups search requests generated by the task objects into fixed-size batches to use with NEST's _msearch API. The caller to this class is delayed until its batch returns. That class is available here.
My framework wraps models the result of each import/export task as either "bool" or "Exception". The overall process is able to continue even if errors with individual items are encountered.
Problem
I am seeing the following exception raised thousands of times after several hours of tasks completing without errors:
System.InvalidOperationException: Current error context error is different to requested error.
at _____.Matcher.<GetBestMatchAsync>d__15.MoveNext() in C:\\_work\\edc7a363\\_____\\Matcher.cs:line 266
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
_____.MatchBlock`1.<ExecuteAsyncInternal>d__19.MoveNext() in C:\\_work\\edc7a363\\_____\\MatchBlock.cs:line 111
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at _____.Block.BlockBase.<ExecuteAsync>d__11.MoveNext() in C:\\_work\\edc7a363\\_____\\Block\\BlockBase.cs:line 33
This is the code throwing the exception (from the bulk searcher class linked above):
try
{
var bulkResponse = Client.MultiSearch(searchDescriptor);
var items = bulkResponse.GetResponses<T>().ToList();
// Set response values and release all waiting tasks
var zip = currentBuffer.Zip(items, (op, result) => new { op, result });
foreach (var a in zip)
{
a.op.Response = a.result;
a.op.Cts.Cancel();
}
}
catch (Exception e)
{
foreach (var op in currentBuffer)
{
op.Error = e;
op.Cts.Cancel();
}
}
where Client is an IElasticClient.
Googling the exception message leads me to this method in the JsonSerializerInternalBase class in JSON.Net, which seems to be executed after each deserialisation:
private ErrorContext GetErrorContext(object currentObject, object member, string path, Exception error)
{
if (_currentErrorContext == null)
{
_currentErrorContext = new ErrorContext(currentObject, member, path, error);
}
if (_currentErrorContext.Error != error)
{
throw new InvalidOperationException("Current error context error is different to requested error.");
}
return _currentErrorContext;
}
Given a single NEST object is being reused for every operation across multiple threads - and I think NEST only uses one JsonSerializer instance - this makes me think this part of JSON.Net is not thread-safe. Though it's strange how the error doesn't start happening until a few hours into a run.
How can I debug this further?
My colleague eventually traced the error down - it was due to an exception being thrown from inside a JsonConverter which was called by another JsonConverter. The "error context" is an internal JSON.Net thing used to track the last exception thrown. Seems like the exception was handled by the wrong JsonConverter. We added a flag to the inner JsonConverter to let it know not to throw the exception in a certain context.
I hit this error when an enum property was being serialised as null with a custom serialiser, then deserialised with the default deserialiser.
I found this can also happen if you are using the JsonSerializerSettings error handler like this:
parsedResponse = JsonConvert.DeserializeObject<T>(
json,
new JsonSerializerSettings
{
Error = (object sender, ErrorEventArgs args) =>
{
throw new MyCustomException(String.Format("Parse error: {0}", args.ErrorContext.Error.Message));
},
...
The thrown error will not be MyCustomException, but rather the "Current error context error is different to requested error". Apparently Json.NET doesn't like it if you throw an exception inside the error handler
I recently started a Microsoft Band application for Windows Phone 8.1.
The application basically uses UV sensors. But the problem here is not the UV, rather just sending the notification.
The code that sends the notification to the Band looks like (And where it goes to the exception):
await bandClient.NotificationManager.SendMessageAsync(tileGuid, "Title", "Body", DateTimeOffset.Now, MessageFlags.ShowDialog);
The full exception is:
(Exception parameter is below this question)
Handled = false
"Device status code: 0xA0D4000A received"
It is thrown from file App.g.i.cs:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
I searched the web for this exception, but no result.
Weird part is, that actually at one point this code worked and sent the notification.
It has also sent some exception about "Transport" and "Stream" something, but I cannot re-product those exceptions again right now.
I have done:
Factory reset the Band and reconnect (Unregister and stuff also).
Restart the phone and try other phones.
Moved the notification to be thrown later or earlier in code.
Does anyone happen to have any ideas or such, what could be done and what could be wrong
Exception parameter:
+ Exception {Microsoft.Band.BandOperationException: Device status code: 0xA0D4000A received.
at Microsoft.Band.BandClient.CheckStatus(CargoStatus status, CommandStatusHandling statusHandling)
at Microsoft.Band.BandClient.SendNotification[T](UInt16 notificationId, Guid& tileId, T& notificationInfo, PooledBuffer payload)
at Microsoft.Band.BandClient.SendMessage(Guid& tileId, String title, String body, DateTimeOffset timestamp, MessageFlags flags, CancellationToken token)
at Microsoft.Band.BandClient.<>c__DisplayClass11.<SendMessageAsync>b__10()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Uvicorn.PivotPage.<ThrowNotification>d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()} System.Exception {Microsoft.Band.BandOperationException}
Make sure to verify that the Tile with the GUID passed to the SendMessageAsync() method has first been added to the Band (for example, after a factory reset).
Are you able to send a notification to the band not going through the tile? Just a vibrate notification? Those do not require the tile. I would like to rule out the tile as the issue.
The following code correctly records audio recorded from my Windows Phone 8 device to isolated storage using the AMR and AAC formats. However, when I try to record the PCM format the app crashes with the error:
Value does not fall within the expected range.
Windows.Phone.Media.Capture.AudioVideoCaptureDevice.StartRecordingToStreamAsync(IRandomAccessStream stream)
at WP8.Classes.AudioCaptureController.<StartRecordingAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WP8.ViewModels.CameraPageViewModel.<capture>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WP8.ViewModels.CameraPageViewModel.<TakePictureAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
The code I have working is as follows:
private AudioVideoCaptureDevice mic;
private IRandomAccessStream sst;
private string path;
public async Task MicStartAsync()
{
mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync();
mic.AudioEncodingFormat = CameraCaptureAudioFormat.Pcm;
}
public async Task StartRecordingAsync()
{
IsolatedStorageAccess iso = new IsolatedStorageAccess();
sst = await iso.SetUpFileStreamForSavingAudioAsync("123.pcm");
await mic.StartRecordingToStreamAsync(sst);
path = iso.Path;
}
public async Task StopRecordingAsync()
{
await mic.StopRecordingAsync();
sst.AsStream().Dispose();
new MediaPlayerLauncher()
{
Media = new Uri(path, UriKind.Relative)
}.Show();
}
}
}
changing the format to anything other than pcm works!
UPDATE: For some reason it now seems to avoid crashing but this is shown in the output:
A first chance exception of type 'System.ArgumentException' occurred in WP8.DLL
An exception of type 'System.ArgumentException' occurred in WP8.DLL and wasn't handled before a managed/native boundary
(WP8 is the name of my dll) The code carries on as normal after this and only crashes when I go to stop the recording where it says the recording never started and the AudioVideoCaptureDevice is in an incorrect state
I have also tried using var AudioVideoCaptureDevice.SupportedAudioEncodingFormats; to check that Pcm is available which it is
you can record from the mic using XNA framework (it seems to that microsoft have an error in there framework when writing data to the file!)
Take a look at this code Microphone Sample and this article for saving data in a wav format Saving Microphone stream to wave format in Windows Phone from Nokia developer portal!