NotSupportedException when adding entity via odata on windows phone - windows-phone-7

I'm using the odata client generator (DataSvcUtil.exe) in a Windows Phone 7 application. Retrieving entities and collections is fine as is updating an existing entity. But when I try to add a new entity, I get a NotSupportedException. Here's my code.
private void Button_Click(object sender, RoutedEventArgs e)
{
Drinks d =new Drink();
d.BarCode = "1234567890";
d.Description = "Test Drink";
d.Quantity = -1;
context.AddToDrinks(d);
context.BeginSaveChanges(SaveChangesOptions.Batch, OnChangesSaved, context);
}
private void OnChangesSaved(IAsyncResult result)
{
Dispatcher.BeginInvoke(() =>
{
try
{
var something = result.AsyncState;
context = result.AsyncState as DrinkTrackerModelContainer;
// Complete the save changes operation and display the response.
ShowSaveResponse("Drink Logged!", context.EndSaveChanges(result));
}
catch (DataServiceRequestException ex)
{
ShowSaveResponse("Error Logging Drink", ex.Response);
}
catch (InvalidOperationException ex)
{
ShowSaveResponse(ex.Message, null);
}
}
);
}
As soon as EndSaveChanges is called, I get the
NotSupportedException.
EDIT: I used fiddler and saw that I was in fact getting a different exception from the service. That exception data was not being shown in the debugger. Once I corrected the actual exception, the insert worked fine.

I think you have first chance exceptions turned on which is causing an internal exception thrown by the client library to surface as an exception. Try turning off First Chance Exceptions in the "Exceptions" menu in VS and running the app.

As you mentioned in your edit, the NotSupportedException was a red herring. I think that when debugging a phone app you will hit the NotSupportedException even if you have cleared the setting to break on unhandled CLR exceptions.
If you continue(F5), you'll hit an actual DataServiceRequestException exception. If it doesn't have enough information to debug it, you can follow the steps in this post to get more detailed information in the exception: http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx
I ran into the same problem yesterday, and after following the steps in the blog I was able to successfully debug the problem.

Related

Where is the exception information when I return InternalServerError from a Web Api?

I'm calling one Web Api (.NET Framework) from another (.NET Core). If the called one returns an InternalServerError(exception), how do I access that exception from the calling code?
The called one does this:
public IHttpActionResult GetAccountTransactions()
{
try
{
// do some stuff
}
catch (Exception e)
{
return InternalServerError(e);
}
}
The calling one does this:
HttpResponseMessage response = await client.GetAsync(url);
...but when I add the response to the watch window in Visual Studio, I can't find the exception information.
Using Fiddler, I confirmed that the exception was included in the response body but it took some work to extract it.
See How can I retrieve passed exception from HttpResponseMessage(HttpStatusCode, Exception)
I tested this answer posted there with .NET Framework, but not with .NET Core.
if(!response.IsSuccessStatusCode){
HttpError error = response.Content.ReadAsAsync<HttpError>().Result;
}

How to throw exception with MessageBox in Xamarin

I'm make an app which get data from API, but sometimes error will occur.
I have throw exception in my code when StatusCode is not Ok. But i have to handle it.
So, my question is how to get the exception on another thread and throw it with message box in xamarin.
ProductsNew = await Task.Run(() =>
{
ProductViewData productNewViewData = new ProductViewData();
return productNewViewData.GetProductNew("5");
});
Thanks for any help.
Put your code in try and catch block and show the error on message box.
try
{
//code
}
catch(Exception ex)
{
DisplayAlert("Error",ex.Message,"Ok");
}

quickbooks online sdk v3 how to troubleshot a badrequest/ValidationException

When debugging a program using the QuickBooks Online API V3 with the SDK. How do you troubleshoot a bad request coming from DataServices. I have gone through several layers of the Exception innerExceptions and I only see ValidationException.
But what tripped the validation exception???
Is there a log to see what caused the problem?
catch (Intuit.Ipp.Exception.IdsException ex)
{
//TODO: handle dupe or other....
var returnMessage = string.Empty;
var innerException = ((Intuit.Ipp.Exception.ValidationException)(ex.InnerException)).InnerExceptions.FirstOrDefault();
if (innerException != null)
{
returnMessage = innerException.Message;
}
}
I just found out this when looking deeply into the exception generated.
Generally speaking you will get an exception and you check if the inner exception object is not null or nothing, if it has an inner exception you look at it.
You will notice that every exception also has a property called "InnerExceptions" (plural) which is a list containing inner exceptions, this property will be null when you have a proper inner exception, but in the last one (in my case) when the inner exception property is null this list contains one inner exception with the details.
This property is available on Intuit.Ipp.Exception.IdsException and contain a list of IdsError
I'm using the IPP .Net SDK 3.0 API (version 2.0.2.0)
For .Net SDK please enable request/response logs. Th details for bad exception get saved in these files.
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/logging
Please mention which SDK(JAVA/.NET/PHP) you are using.
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits
You can set the logger to debug mode to capture the raw request and response XMLs. From the response XML, you'll get the details of failure(if any).
Otherwise, you can call these endpoints directly from APIExplorer.
https://developer.intuit.com/apiexplorer?apiname=V3QBO
Thanks
Simply collect the Error Message coming from Quickbook API. Make following the first catch block statement:
catch (Intuit.Ipp.Exception.IdsException ex)
{
string errorMessage = (((Intuit.Ipp.Exception.ValidationException)(ex.InnerException)).InnerExceptions.FirstOrDefault() ?? new Exception()).Message;
// you can further log the error .
}

Is updating LiveTile on Application_Deactivated a good practice?

I have not used Background Agents for updating LiveTiles. I update the tile on exiting of the app and on Application_Deactivated.
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
CycleManager pCycMan = CycleManager.Instance;
pCycMan.WriteToIsolatedStorage();
ResourceManager resMan = new ResourceManager("xxx.AppResources", Assembly.GetExecutingAssembly());
ShellTile PrimaryTile = ShellTile.ActiveTiles.First();
StandardTileData tile = new StandardTileData();
try
{
if (PrimaryTile != null)
{
tile.BackTitle = resMan.GetString("liveTileTitle");
tile.BackBackgroundImage = new Uri("/Background.png", UriKind.Relative);
if (pCycMan.GetStartDate() == pCycMan.GetDefaultDate())
{
tile.Title = resMan.GetString("liveTileNotTrackingStatus");
}
else
{
tile.Title = m_liveTileText;
}
PrimaryTile.Update(tile);
}
}
catch(Exception)
{
}
}
Is is a good practice to do so? The app is published and I have received a StackTrace with a COMException. It shows that the exception is raised on execution of Microsoft.Phone.Shell.ShellTile.Update after the XXX.App.Application_Deactivated
Does anyone know of this exception or faced such situations? It would be really helpful if someone could guide me on this.
When the Application_Deactivated event is raised, you have 10 seconds to finish your task.
After that, your application will be terminated.
So maybe the crash happened because your code took more than 10 seconds to complete.
I used to update the livetile in the Application_Deactivated, however this caused issues with resuming, so I removed that feature.
Someone else found the same issue and updates in a different area:
http://www.japf.fr/2012/12/updating-the-live-tiles-when-the-exits-wp8-weirdness/

How to call webservice methods in Windows Phone 7?

For connecting to webservices i wrote the following code.
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://www.Webservices.asmx"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
void wc_DownloadStringCompleted(object sender,DownloadStringCompletedEventArgs e)
{
Debug.WriteLine("Web service says: " + e.Result);
using (var reader = new StringReader(e.Result))
{
String str = reader.ReadToEnd();
}
}
by using above code Get the string result.But i want get the result in HTMLVisulaizer then i know the what are the methods having that webservice.then i can easily access the particular method.
Please tell me how to call a web service method in Windows phone 7?in webservice i am having 5 webmethods.how to get that and how to call the Particular webmenthod.
Please tell me thanks in advance.
#venkateswara Are you talking about obtaining a list of known WebReference methods so you know which one to call in you code? Do you not see the this of known method calls when you add the WebReference to your WP7 project? Since you will be developing the WP7 app in VS I can't see the reason you would want to do this. Even if you don't own the webservice yourself, you will need to connect to it from VS in order to add the reference to your project.
Below is the screen in VS2010 where a WebReference is added. The Operations are listed on the right.
Once added you can use the ObjectBrowser to understand how the methods should be called.
Please let me know if I have missed something from your question.
#Jason James
The first step:
You must add referent Services ,like Jason James has very detailed instructions .
step 2 :
You can open App.xaml.cs , in Functions Apps
public Apps()
{
// Global handler for uncaught exceptions.
UnhandledException += Application_UnhandledException;
// Show graphics profiling information while debugging.
if (System.Diagnostics.Debugger.IsAttached)
{
// Display the current frame rate counters.
Application.Current.Host.Settings.EnableFrameRateCounter = true;
// Show the areas of the app that are being redrawn in each frame.
//Application.Current.Host.Settings.EnableRedrawRegions = true;
// Enable non-production analysis visualization mode,
// which shows areas of a page that are being GPU accelerated with a colored overlay.
//Application.Current.Host.Settings.EnableCacheVisualization = true;
}
// You can declare objects here that you will use
//Examlpe: NameservicesReferent.(Function that returns services) = new NameservicesReferent.(Function that returns services)();
Ws_Function = new Nameservices.ServiceSoapClient();
}
step 3:
in Mainpage.xaml.cs
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted += new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
GlobalVariables.***NameWedservise***.getLinkAdvertiseIndexAsync("**parameters to be passed**");
step 4:
void Ws_advertise_getLinkAdvertiseIndexCompleted(object sender, advertise.getLinkAdvertiseIndexCompletedEventArgs e)
{
//function returns the results to you, the example here is an array
string[] array = null;
try
{
array = e.result;
if(array != null)
}
cath(exception ex)
{
}
finally
{
array = null;
GlobalVariables.Ws_advertise.getLinkAdvertiseIndexCompleted -= new EventHandler<advertise.getLinkAdvertiseIndexCompletedEventArgs>(Ws_advertise_getLinkAdvertiseIndexCompleted);
}
}

Resources