|
The inner exception may have an inner exception, and so on. Instead of throwing the inner exception, I'd throw the outer one, as it would (should) contain all inner-exceptions.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Since Task.Exception is an AggregateException you've gotta worry about multiple inner exceptions in addition to the current exception the AggregateException represents unless you know precisely how many exceptions can be thrown. My ideas:
Log current exception, flatten (in the case of nested AggregateExceptions ), and re-throw:
_hubProxy.Invoke("SomeMethodName", model).ContinueWith((t) =>
{
if (t.Exception != null && t.Exception.InnerException != null)
{
throw t.Exception.Flatten();
}
});
Handle exceptions you know how to handle, re-throw the rest:
_hubProxy.Invoke("SomeMethodName", model).ContinueWith((t) =>
{
if (t.Exception != null && t.Exception.InnerException != null)
{
AggregateException ae = t.Exception.Flatten();
ae.Handle(x =>
{
if (x is IndexOutOfRangeException)
{
return true;
}
return false;
});
}
});
You can avoid Flatten() if you're absolutely sure there are no tasks inside your task. Also the reason I used Handle() is because it conveniently re-wraps all exceptions that did not return true (not handled) in an AggregateException and re-throws them. If you can handle everything or are sure of exactly what exceptions can be thrown you could iterate over the AggregateException.InnerExceptions collection instead and re-throw as you desire.
EDIT: Quick addendum: If you're using C#6 you can simply the if-statement to:
if (t.Exception?.InnerException != null)
Looks cleaner to me but to each their own 
modified 4-Jan-17 21:37pm.
|
|
|
|
|
This is why I am no longer interested in helping him. If he showed even a touch of progression or having learned a lesson, I would still help out.
This space for rent
|
|
|
|
|
I don't understand this response to my question
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I'm guessing it should have been part of the thread above
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It should - my connection to CP was doing all sorts of funny things this morning. Your questions I'm fine with. It's the help vampire above that I am not interested in helping any more.
This space for rent
|
|
|
|
|
I posted this tip that tries to see if an exception in the chain is of a particular type. You could use the code as a basis for bending it to your will.
Find your inner exception
(I don't know what's going on with link pasting.)
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Very nice. Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I am trying to keep thread/process active, when application is minimized to tray. As i want some tasks to be performed in background in app state = minimize.
As I have defined a async delegate to capture a callback for an event, when the app is minimized the process is completed and the app is supposed to listen for event fire, but when the app is minimized the app does not reports to the event, and the callback to the delegate doesn't occurs but the following event fire and all the respective tasks are performed when app is maximized.
Please guide and help me.
|
|
|
|
|
hassaan mustafa wrote: I am trying to keep thread/process active, when application is minimized to tray Applications do not "minimize to tray". Your process is running and may show a TrayIcon. What you do on "minimize" is completely up to you.
The thread/proces remains active until you exit. So, the obvious idea is not to quit the application when you are "minimizing".
Show us some code and you may get a more specific and/or better answer.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi!
I have published a Microsoft Dynamics NAV page as an OData web service V4.
I used Odata v4 Client Code Genrator ver 2.4.0 to create the Client side proxy classes for my C# project.
When I make a simple call to "myhost/.../Company" everything works like a charm using simple code like this:
NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4"));
NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
List<NAVEntities.Company> company = NAVCient.Company.ToList;
I get my list of available Companies. Now I want to get the CustomerCards for my selected Company. I do like this:
NAVCient = new NAVEntities.NAV(new Uri("myhost/.../ODataV4/Company('MyTest')"));
NAVCient.Credentials = new Net.NetworkCredential("usr", "psw");
List<NAVEntities.Customer_Card> Customers = NAVCient.Customer_Card.ToList;
The uri genrated is correct and I can see the response comming back correct using fiddler with all my data. Code gets an exception trying to parse the information. At first i thought the backend had some issues but clearly its the client producing this error bec in fiddler I can see my result and nothing else as a response from server :
"An unhandled exception of type 'Microsoft.OData.Core.ODataException' occurred in Microsoft.OData.Core.dll
Additional information: When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written."
Any suggestions/advice?
I have tried other sources and they work as it seem.
Thanks for your help
// henrik
Tags:
|
|
|
|
|
You haven't said specifically which statement is failing.
I would try:
var Customers = NAVCient.Customer_Card;
... = Customers.ToList();
etc.
instead of:
List<NAVEntities.Customer_Card> Customers = NAVCient.Customer_Card.ToList;
And see how far I get from there.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
It is failing on the .ToList part ...
Its very wierd. Tried that thing but same. And wierdest of all why is it trying to write a JSON-response? Sounds more like something from server?
|
|
|
|
|
That was the point.
Inspect the "var" using the debugger before performing the "ToList" and see what you're getting versus what you're expecting.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Will take a look into it ...
Getting back to you!
|
|
|
|
|
The object returned is :
Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)
The object created by the Client generator. I need to call .Execute or something else with collection to
make it execute the query.
If I do that I get :
Microsoft.OData.Client.QueryOperationResponse(Of Customer_Card)
The execution seem ok. Problem is when I start enumerating through the list that shold have been produced. I can clearly see in fiddler that result comming back to me is ok. Something is happening on clientside. Maybe the call itself to the service is doing something wierd. But why should it do that when it works on the query for Company.
Can this has to do with child/relations spec maybe?
Thanks ZD
|
|
|
|
|
You say execution "seems ok" .... Hardly a show of confidence.
Instead of assuming it is "ok", there are a number of properties in the response you should look at (e.g. "Error") to confirm that everything is as it should be.
QueryOperationResponse Class (System.Data.Services.Client)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Trying executing .Execute on the object of type :
Global.Microsoft.OData.Client.DataServiceQuery(Of Customer_Card)
Gives me this object and I can see in fiddler that response is received and correct but accoring to error TotalCount is missing:
https://postimg.org/image/eyv1hglnj/
However I got the objext I am supposed to.
If I try to call .ToList it first makes call to .Execute and then try to create :
System.Collections.Generic.List(Of NAVEntities.Customer_Card)
But it produces an error and I the object looking like this:
https://postimg.org/image/e3ewt9b5j/
Full stacktrace is:
Microsoft.OData.Core.ODataException was unhandled
HResult=-2146233079
Message=When writing a JSON response, a user model must be specified and the entity set and entity type must be passed to the ODataMessageWriter.CreateODataEntryWriter method or the
ODataFeedAndEntrySerializationInfo must be set on the ODataEntry or ODataFeed that is being written.
Source=Microsoft.OData.Core
StackTrace:
at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.ValidateAndReturn[T](T value)
at Microsoft.OData.Core.ODataFeedAndEntryTypeContext.get_NavigationSourceName()
at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeId()
at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.ComputeAndCacheId()
at Microsoft.OData.Core.Evaluation.ODataConventionalEntityMetadataBuilder.GetId()
at Microsoft.OData.Client.Materialization.MaterializerEntry.UpdateEntityDescriptor()
at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.ReadEntryCore()
at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.TryReadEntry(MaterializerEntry& entry)
at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.<LazyReadEntries>d__0.MoveNext()
at Microsoft.OData.Client.Materialization.FeedAndEntryMaterializerAdapter.Read()
at Microsoft.OData.Client.Materialization.ODataReaderEntityMaterializer.ReadNextFeedOrEntry()
at Microsoft.OData.Client.Materialization.ODataEntityMaterializer.ReadImplementation()
at Microsoft.OData.Client.MaterializeAtom.MoveNextInternal()
at Microsoft.OData.Client.MaterializeAtom.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__94`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Data.WebServices.ODataTestApp.MainModule.Main() in Data.WebServices.OData.TestApp\MainModule.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Update : I Have error on TotalCount on the Company-call that worked so thats not the case.
modified 5-Jan-17 1:26am.
|
|
|
|
|
Unfortunately, you're posting "code fragments"; which makes it hard to discern what you are or are not doing.
You previously hinted it might be a "relation" thing; yes, data services does "lazy loading"; cannot tell from your post if you addressed this.
How to: Load Related Entities (WCF Data Services)
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Lets see if I can put up a sample thing for you.
Yes lazyloading might be a thing just like in EF. Need to turn it off maybe?
Thanks // zd
|
|
|
|
|
Cant see anything in fiddler that draws me into that relation-direction. Its just plain-data. Have to dive deeper into that.
|
|
|
|
|
I'm thinking the possibility that from Main () can access its copy of Name_Common to do Name_Common.Cls_Common.StCommon = new Name_Common.St_Common(); For now I do not know how to do it because there is an error. So when I want to use a class, I can copy Main's global structure to that of the class. I have remembered that I did a function to make (cast) of one estrcuture to another one.
For now I can not make new Name_Common.St_Common(); of Main(). The brain has stopped me for days. I can also someone something about points 2 and 3 of debugger employment? Thank you.
|
|
|
|
|
What has this got to do with this question? Please don't hijack others posts.
This space for rent
|
|
|
|
|
|
I am on to it ...
Getting back ...
//zd
|
|
|
|