SignalR Error: Failed to bind arguments received in invocation '(null)' - c#

In my SignalR client (WinForms) I'm getting the following exception on just one method. The callback code is:
onUpdate = Client.HubService.On<Job>("MyMethod", o => MyMethod(o));
And the exception is:
Microsoft.AspNetCore.SignalR.Client.HubConnection: Error: Failed to bind arguments received in invocation '(null)' of 'MyMethod'.
System.InvalidOperationException: There are no callbacks registered for the method 'MyMethod'
bei Microsoft.AspNetCore.SignalR.Client.HubConnection.ConnectionState.Microsoft.AspNetCore.SignalR.IInvocationBinder.GetParameterTypes(String methodName)
bei Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.ParseMessage(ReadOnlySequence`1 input, IInvocationBinder binder)
The call in the server is:
await hubContext.Clients.All.MyMethod(entity);
Everything looks like it's setup correctly. However I always get the exception.
What am I missing?

Related

Unhandled ObjectDisposedException C#

I'm programming a wiki with razor pages in the blazor framework.
Everything was going fine, then I got this error message:
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database 'aspnet-InternesWiki-8BAA8CA5-BC83-4528-BE5F-4E702A44D17F' on server '(localdb)\MSSQLLocalDB'.
fail: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[8]
Failed to invoke hub method 'ConnectCircuit'.
System.ObjectDisposedException: Cannot access a disposed object.
at Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost.SetCircuitUser(ClaimsPrincipal user)
at Microsoft.AspNetCore.Components.Server.ComponentHub.ConnectCircuit(String circuitIdSecret)
at lambda_method11(Closure , Object )
at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.ExecuteMethod(ObjectMethodExecutor methodExecutor, Hub hub, Object[] arguments) at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.g__ExecuteInvocation|16_0(DefaultHubDispatcher1 dispatcher, ObjectMethodExecutor methodExecutor, THub hub, Object[] arguments, AsyncServiceScope scope, IHubActivator1 hubActivator, HubConnectionContext connection, HubMethodInvocationMessage hubMethodInvocationMessage, Boolean isStreamCall)
This is where the error occurs:
public async Task<bool> Insertiket(Eintrage eintag)
{
_context.Eintrage.Add(eintag);
_context.SaveChangesAsync();
return true;
}
SaveChangesAsync() It is no longer executed.
Hopefully you can help me, I don't know what to do.
Many thanks in advance
all project files:
https://anonfiles.com/j1c4Fet1y1/InternesWiki_7z
Reading the exception carefully, we see this:
Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[8] Failed to invoke hub method 'ConnectCircuit'. System.ObjectDisposedException: Cannot access a disposed object.
It's not a database issue, it's a SignalR one. By reading the SignalR Hubs API Guide at the Hub Object Lifetime section we learn this:
Because instances of the Hub class are transient, you can't use them to maintain state from one method call to the next. Each time the server receives a method call from a client, a new instance of your Hub class processes the message
Now, I don't have the full picture of your architecture, my guess is that you have multiple method calls with that db write operation at the end, when the original Hub class generated at the first method call had already been disposed.

UseHeaderPropagation not recognized during debug run

I'm working on adding propagation to HotChocolate GraphQL server but simply can't get it working.
I've configured my propagation in my ConfigureServices services.AddHeaderPropagation(o => o.Headers.Add("Authorization"));
I've added it to my httpClient: services.AddHttpClient(AssumptionManagement, c => c.BaseAddress = new Uri("http://localhost:19801")).AddHeaderPropagation();
I've added it in my Configure method:
app.UseHeaderPropagation();
Despite all this it still gives me the following error when I run the app in debug:
An unhandled exception of type System.InvalidOperationException occurred in System.Private.CoreLib.dll: The HeaderPropagationValues.Headers property has not been initialized.
Register the header propagation middleware by adding app.UseHeaderPropagation() in the Configure(...) method. Header propagation can only be used within the context of an HTTP request.'
Am I just not seeing something here or what am I doing wrong?

Why is my Azure function not recording the correct exception in App Insights?

Let's say my function is the following:
public static void Run([QueueTrigger(queueName, Connection = connection)]string message,
TraceWriter logger) {
throw new CustomException();
}
Here's what the log looks like:
SomeTime [Error] ExceptionNameSpace.CustomException ---> System.Exception
When I go to App Insights and view the exception breakdown, I find this failed request under the "Exception" type. I don't even see a CustomException type listed! Why is my exception being transformed into a generic exception?
For those of you who ran into the same issue:
I found the "solution" for this by being able to recover my original exception by querying for the outerType column in the exceptions table inside the Analytics part of App Insights. Strange that the generic exception shows up under the "type" column but "outerType" is my original exception.

How to handle OdataException in DefaultODataPathHandler.Parse at global level?

DefaultODataPathHandler.Parse(string serviceRoot, string odataPath, IServiceProvider requestContainer)
is throwing ODataException when I try to send a wrong data type to a
OData controller function. For example, calling GetOrders(date = 20181001), (with an integer instead of a date (2018-10-01)), throws ODataException with message:
not able to cast Edm.Int32 to Emd.DateTime
How can I handle this exception at global level?

How do you mock IContextChannel in a WCF ServiceAuthorizationManager?

I am trying to write unit tests for a custom ServiceAuthorizationManager. The call to CheckAccessCore takes an OperationContext as a parameter. To instantiate an OperationContext, one must pass an IContextChannel to the constructor. Using MOQ, I've declared an IContextChannel:
private OperationContext _context;
private Mock<IContextChannel> _contextChannelMock;
Then I attempt to create the OperationContext:
_context = new OperationContext(_contextChannelMock.Object);
But this line throws an exception:
Result Message: Initialization method
Urs.EnterpriseServices.Providers.Tests.UrsServiceAuthorizationManager_Tests.SetUp
threw exception. System.InvalidOperationException:
System.InvalidOperationException: Invalid IContextChannel passed to
OperationContext. Must be either a server dispatching channel or a
client proxy channel..
How do I mock, a server dispatching channel?
You can't directly. See if WCFMock will help.

Categories