i've been implementing a listener that responds to an OnMessageAsync. This works exactly as intended but in the debug feed it continually triggers these exceptions:
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.ServiceModel.FaultException`1' in Microsoft.ServiceBus.dll
Exception thrown: 'System.TimeoutException' in Microsoft.ServiceBus.dll
This set of 6 exceptions seem to trigger every minute. Does anyone know why these trigger or what exactly is causing these exceptions?
code snippet:
OnMessageOptions options = new OnMessageOptions
{
MaxConcurrentCalls = 5,
AutoComplete = false
};
QueueClient client = QueueClient.CreateFromConnectionString(inboundConnectionString, ReceiveMode.PeekLock);
client.OnMessageAsync(async m =>
{
try
{
await ProcessMessageAsync(m);
...
}
...
}, options);
AutoRenewTimeout doesn't seem to make a difference in OnMessageOptions.
Related
I was hoping somebody could enlighten me a little bit on an issue I am facing in regards to async/await exception handling with HttpClient. I have written some code to illustrate, and it is being excecuted on both a Windows Phone 8 device and the emulator:
private async void SearchButton_Click(object sender, EventArgs e)
{
try
{
HttpClient client = new HttpClient();
System.Diagnostics.Debug.WriteLine("BEGIN FAULTY REQUEST:");
string response = await client.GetStringAsync("http://www.ajshdgasjhdgajdhgasjhdgasjdhgasjdhgas.tk/");
System.Diagnostics.Debug.WriteLine("SUCCESS:");
System.Diagnostics.Debug.WriteLine(response);
}
catch (Exception exception)
{
System.Diagnostics.Debug.WriteLine("CAUGHT EXCEPTION:");
System.Diagnostics.Debug.WriteLine(exception);
}
}
Tapping the button that invokes this function, produces the following output in the debugger console, the most interesting being the ones in bold:
BEGIN FAULTY REQUEST:
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
A first chance exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.ni.dll
An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
CAUGHT EXCEPTION:
(and here it prints out the HttpRequestException)
Of course I am expecting an error in this case since the URL I am calling is nonsense. What I am not understanding here, is why the debugger reports that the exceptions are not handled, when the output simultaneously reports that the exception is caught. Also, the UI side of the app becomes much less responsive while the output is being printed, indicating that something is probably amiss.
Is this not the way to handle exceptions when working with async and await? I appreciate any input! Thanks.
As you are using HttpClient, try to use response.EnsureSuccessStatusCode();
Now HttpClient will throw exception when response status is not a success code.
try
{
HttpResponseMessage response = await client.GetAsync("http://www.ajshdgasjhdgajdhgasjhdgasjdhgasjdhgas.tk/");
response.EnsureSuccessStatusCode(); // Throw if not a success code.
// ...
}
catch (HttpRequestException e)
{
// Handle exception.
}
ORIGINAL SOURCE OF THE CODE: http://www.asp.net/web-api/overview/advanced/calling-a-web-api-from-a-net-client
This is an artifact of the debugger. It's determining that an exception is "uncaught" because it's not caught yet. In this case this is expected behavior.
You are handling the exceptions correctly.
The debugger is telling you that this exception is first chance. When a debugger is attached to your process it gets notified for every exception that is thrown and then based on how the debugger has been configured it will decide what to do with it. You can go through What is first chance exception? for more details.
On a side note, catch specific exceptions only so that you understand which exceptions you are expecting and why.
I got this exception while try to update the badge count using the following below code
BadgeUpdater badgeUpdater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
// And update the badge
badgeUpdater.Update(badge);
I'm a newbie on Service Fabric and, im my exercises, I've done a Reliable Stateless Service that, in RunAsync, increments his attribute "counter". I verified that I can expose via interface IService a method that returns this counter values (method called from a client via ServiceProxy), obviously overriding CreateServiceInstanceListeners and adding CreateServiceRemotingListener.
Then I tried to add another custom communication listener SS1ServiceEndpoint (that listen on a specified port 7080):
<Endpoint Name="RemoteListener" />
<Endpoint Name="SS1ServiceEndpoint" Protocol="http" Port="7080" Type="Input" />
but the service throws initially
Exception thrown: 'System.ArgumentException' in Microsoft.ServiceFabric.FabricTransport.dll
Then the OpenAsync method of the custom listener is called more and more times and after each call another exception is thrown:
Exception thrown: 'System.ObjectDisposedException' in mscorlib.dll
Exception thrown: 'System.AggregateException' in mscorlib.dll
Exception thrown: 'System.Fabric.FabricElementAlreadyExistsException' in
System.Fabric.dll
Exception thrown: 'System.ArgumentException' in
Microsoft.ServiceFabric.FabricTransport.dll
If I remove CreateServiceRemotingListener in CreateServiceInstanceListeners, the service starts and I can call it from browser on the listening port.
My question is: are multiple listeners not supported? I've not tried with two custom listeners (on different port).
Multiple listeners are supported, but you have to provide a name for the listeners, which is otherwise optional. Try adding a name for your listeners in your CreateServiceInstanceListeners.
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[]
{
new ServiceInstanceListener(context => this.CreateServiceRemotingListener(context), "RemotingListener"),
new ServiceInstanceListener(context => new CustomListener(), "CustomListenerName")
};
}
I'm using Microsoft.VisualStudio.TestTools.UnitTesting for unit testing.
I have this test which asserts that an exception was thrown and it is failing
[TestMethod]
public async Task ShouldThrowHttpExceptionIfPassedObjectIsNull()
{
_mockLogger = new Mock<ILogger<DataService>>();
// setup memoryCache
object expected = null;
_mockNullMemoryCache = MockMemoryCacheService.GetNullMemoryCache(expected);
_mockSessionManagementService = new MockSessionManagementService();
_ds = new DataService(
_mockLogger.Object,
_mockNullMemoryCache.Object,
_mockSessionManagementService
);
Assert.ThrowsException<HttpException>(() => _ds.RetrieveFileData<object>(_incorrectFilePath, false));
}
When I debug it, the last line of code to run before it errors out and fails is this:
The exception ex is a system.invalidOperationException but that shouldn't matter because it throws an HttpException not matter what. Why is the test failing with the reason:
Test Name: ShouldThrowHttpExceptionIfPassedObjectIsNull Test
FullName: xxx.xxx.xxx.xxx.ShouldThrowHttpExceptionIfPassedObjectIsNull
Test
Source: C:\Users\xxx\xxx.cs
: line 88 Test Outcome: Failed Test Duration: 0:04:35.5251661
Result StackTrace: at
xxxxxx.d__10.MoveNext()
in
C:\Users\xxx\xxx\xxx.cs:line
101
--- 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) Result Message: Assert.ThrowsException failed. No exception
thrown. HttpException exception was expected.
EDIT
The code then moves into this code block after the image:
else
{
// Parsing issue
_logger.LogError(string.Format("Id={0}, Could not retrieve data from {1} : Malformed source data", _sessionManagementService.SessionId, url));
throw new HttpException(HttpStatusCode.InternalServerError, "Malformed source data", true);
}
As it is throwing the HttpException above, it throws a DllNotFoundException.
Exception thrown: 'System.DllNotFoundException' in
System.Private.CoreLib.ni.dll
Additional information: Unable to load DLL 'combase.dll': The
specified module could not be found. (Exception from HRESULT:
0x8007007E)
When I look at the type hierarchy of HttpException, I see that it doe not inherit from InvalidOperationException. Therefore the unit test fails correctly.
Likely there's some LINQ code or other code which cannot execute correctly, therefore catches the HttpException and converts it into the InvalidOperationException.
You should be able to debug the unit test. Instruct Visual Studio to stop at exceptions, then go forward step by step and try to find out where your exception gets converted, e.g. when you step through some LINQ code.
The MoveNext() call indicates that something tries to loop over values. When debugging, disable Just my code, because it could be in the .NET framework.
I wrote a code in asp.net that read data from files and draw a graph.
It worked but after awhile when i run the program, this exception arise
"An unhandled exception of type 'System.StackOverflowException'
occurred in mscorlib.dll"
in this statement in the code:
if (File.Exists(fName)) <----(here is the exception)
{
stream = File.Open(fName, FileMode.Open);
g_day = Deserialize(stream);
stream.Close();
int cn = 0;
if (g_day.Values.Count != 0)
cn = g_day.Values[g_day.Values.Count - 1].Value;
Label1.Text = cn.ToString();
}
Your function is probably calling itself recursively an infinite number of times. Sometimes this happens indirectly (you call a method in the BCL and it calls back to your code, and this keeps repeating). File.Exists is probably not the culprit. Look at your call stack when the error occurs.