Client results - SignalR - .Net 7 - signalr

I'm trying to use the new signalR client results feature that was first announced on .Net 7 preview 4 https://devblogs.microsoft.com/dotnet/asp-net-core-updates-in-dotnet-7-preview-4/ and recently released in .NET 7 https://devblogs.microsoft.com/dotnet/announcing-asp-net-core-in-dotnet-7/.
Therefore, I'm upgrading an existing signalR application to .NET 7. But I didn't find examples on how to implement the feature. If you click the link from the .NET 7 release, it leads you to a confusing page with no information about the feature. The page from preview 4 has a small code snippet but when I try to use it, I get a IHubCallerClients does not contain a definition for 'Single' and no accessible extension method 'Single' accepting a first argument of type 'IHubCallerClients' could be found (are you missing a using directive or an assembly reference?) error.
The server side of the application is currently using Microsoft.AspNetCore.SignalR 1.1.0 package that, by the way, is marked as deprecated. I didn't find any clear information about an alternative to this package...
I made a simple hub to test the snippet from the preview 4 link, also using Microsoft.AspNetCore.SignalR 1.1.0 and .Net 7, where I also get the error I mentioned.
public class HubTest : Hub
{
public async override Task OnConnectedAsync()
{
}
public async override Task OnDisconnectedAsync(Exception exception)
{
}
public async Task WaitForResult(string connectionId)
{
var randomValue = Random.Shared.Next(0, 10);
var result = await Clients.Single(connectionId).InvokeAsync<int>(
"GetResult", "Guess the value between 0 and 10.");
if (result == randomValue)
{
await Clients.Client(connectionId).SendAsync("EndResult", "You guessed correctly!");
}
else
{
await Clients.Client(connectionId).SendAsync("EndResult", $"You guessed incorrectly, value was {randomValue}");
}
}
}
Am I missing something or doing something wrong ? Should I be referencing another package ? Is there anything else I should do or set to be able to use the feature ?
I must confess I'm a bit loss due to the lack of documentation regarding the feature. I searched a lot for info about it, but didn't find anything really interesting. Do you guys have something in mind with examples about this topic ?
Thanks in advance.

We renamed Single back to Client. The documentation has been updated to reflect this.

Related

Async suffix in a method name now deprecated?

VS2022, Asp.Net MVC .Net 6.0
When a function name ends with "async", the url never works. Cannot figure out why. New routing defaults, new "guidelines" enforced or simply a bug?
//works (example https://localhost:7215/home/getuserlist)
public async Task<IActionResult> GetUserList()
//doesn't work (example https://localhost:7215/home/getuserlistasync)
public async Task<IActionResult> GetUserListAsync()
//works (example https://localhost:7215/routetest)
[Route("routetest")]
public async Task<IActionResult> GetUserListAsync()
It is indeed a known behavior, albeit poorly documented. You may call it a bug if you'd like.
The original bug report can be found here, very similar to what you've described: https://github.com/dotnet/aspnetcore/issues/4849
The corresponding issue is here: https://github.com/dotnet/docs/issues/14716. The intention is to trim the suffix from the action name, because it upsets routing and link generation. They even propose a workaround:
services.AddMvc(options =>
{
options.SuppressAsyncSuffixInActionNames = false;
});
Although there are some reports that line might not work. Very confusing!
And here is the discussion that sheds some light on why the behavior you are observing isn't fixed yet: https://github.com/dotnet/aspnetcore/issues/8998. There is even a pull request that wasn't merged because there was no agreement on how to properly trim this suffix from the action name without breaking various common routines (think nameof()) and naming conventions: https://github.com/dotnet/aspnetcore/pull/39128.

How to send list as parameter for search in angular service to .net core

Please Help me I need to retrieve a list of details using a list of parameters. How to achieve that from angular 10 and .net Core?
Also, Single Entries is working for search. But If I try to enter a second entry in the input field and tried to search it is not working.
The method name is GetPodForwardings.
This is the Method in angular (Service)
GetPodForwardings(conNo,newPage,pageSize)
{
return this.http.get(`${this.BaseUrl}Pod/GetConsignmentList?conNo=${conNo}&newPage=${newPage}&pageSize=${pageSize}`)
}
In .NET Controller
[Microsoft.AspNetCore.Mvc.Route("GetConsignmentList")]
[HttpGet]
public async Task<IActionResult> GetListofConsignments([FromQuery]List<long> conNo,int currentPage,int pageSize)
{
return await ProcessQuery(new GetListofConsignmentByConsignmentNoQuery(conNo,currentPage,pageSize));
}
The proper way of adding parameters to an url in Angular is to use the second options parameter of the http.get("url",options) function. Unfortunatly they don't accept arrays rightaway (there is an open github issue).
However string interpolation like you did should also work. You seem to just have the wrong format. As this is treated very framework specific look at this answer to get the right format for your case.

Can't find TraceConfigruation reference (StackDriver ASP.Net setup)

I'm following the setup instructions for Setting up StackDriver Trace for C# ASP.NET. In the section "Configuring the client library", step 3:
In the Global.asax.cs file's WebApiApplication class add teh following Init code block to initialize trace:
public override void Init()
{
string projectId = ConfigurationManager.AppSettings["projectId"];
// ...
base.Init();
TraceConfiguration traceConfig = TraceConfiguration
.Create(bufferOptions: BufferOptions.NoBuffer());
CloudTrace.Initialize(this, projectId, traceConfig);
}
The TraceConfiguration object doesn't exist in either of the client libraries referenced in step 2:
using Google.Cloud.Diagnostics.AspNet;
using Google.Cloud.Diagnostics.Common;
I can't find any reference to this object, and doesn't appear to be built-in to the .net framework.
Assuming you're using this:
https://cloud.google.com/trace/docs/setup/aspnet
If I'm following this correctly, I think the documentation is out-of-date and TraceConfiguration was replaced with TraceOptions some time ago:
https://github.com/googleapis/google-cloud-dotnet/pull/1120
And:
TraceOptions
I'll ping the folks on the PR and who contribute to this library, let's see whether I can get them to help you and -- if necessary -- correct the docs.

SPDispose Ignore attribute not ignoring

In my SharePoint code, I have the following line:
SPWeb web = site.RootWeb; //site is an SPSite object
When I rebuild my project and run the SPDispose tool on the assembly, I get the following error:
Module: Blah.SharePoint.Features.Core.dll Method:
Blah.SharePoint.Features.Core.Helpers.FeatureDeploymentHelper.RemoveWebPartFiles(Microsoft.SharePoint.SPFeatureReceiverProperties,System.String)
Statement: web := site.{Microsoft.SharePoint.SPSite}get_RootWeb()
Source:
C:\xxx\xxx\Main\Source\SharePoint\Features\Core\Helpers\FeatureDeploymentHelper.cs
Line: 26
Notes: Disposable type not disposed: Microsoft.SharePoint.SPWeb
***This may be a false positive depending on how the type was created or if it is disposed outside the current scope More Information:
http://blogs.msdn.com/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx#SPDisposeCheckID_140
What I want to do is to have the SPDispose tool ignore this error, so I have pulled the SPDisposeCheckIgnore class and supporting enum into my project, and I've decorated my method appropriately:
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed.")]
public static void RemoveWebPartFiles(SPFeatureReceiverProperties properties, string assemblyName)
{
...
}
After doing all of this, I still receive the error. Anyone know how I might go about getting rid of that error?
Two things need to be done here.
1) The SPDisposeCheckIgnore class must be defined in the SPDisposeCheck namespace. You CANNOT have your own namespace. See the related comment on this page: http://archive.msdn.microsoft.com/SPDisposeCheck/
2) Anything you are trying to ignore within RunWithElevatedPrivleges must be pulled into an external method or it will not be recognized. This was not being done in the example above, but was being done in other places.
These two rules must be followed for ignore to work. Hope this helps someone else down the road.
Double check how you're retrieving and assigning the RootWeb object. If it's done in an external method, the DisposeChecker might not pick up that it's a RootWeb reference.
I don't see anything wrong with what you've written. I pulled out getting the root web into a static method so I only had to ignore this error in one place, and it works in anonymous delegates. The following worked for me:
public class DisposeUtils
{
[SPDisposeCheckIgnore(SPDisposeCheckID.SPDisposeCheckID_140, "RootWeb does not need disposed. http://blogs.msdn.com/b/rogerla/archive/2009/11/30/sharepoint-2007-2010-do-not-dispose-guidance-spdisposecheck.aspx")]
public static SPWeb GetRootWeb(SPSite site)
{
return site.RootWeb;
}
}
Sorry, I'm not sure if that helps exactly - I'm saying your code should work. Have you checked SPDisposeCheck to see how it handles 'Documented' and 'Undocumented' errors? (I've never been entirely clear what those settings do)

Rolling back code from .net 4.0 to .net 3.5 and now dynamics dont work

I have used the KEYWORD dynamic and it is only available in .net 4.0 but I have to roll-back to a .net 3.5 server. I can not use KEYWORD dynamic anymore and need to convert it to work with .net 3.5. I have a class, FBWeird,that I thought I could cast against but it doesn't work when I put it in fb.Query(query). I use this same method when I rolled back a .Get statement and .Get(id) works for me but not in this instance. Can anyone help me with the below code to get it back working?
CODE
var fb = new FacebookWebClient(accessToken.ToString());
var fbResults = fb.Query("SELECT like_count,normalized_url FROM link_stat WHERE url='http://www.facebook.com/cocacola");
long likeCount = fbResults.like_count;
Response.Write(fbResults.ToString());
CLASS
public class FBWeird
{
public string like_count { get; set; }
}
EDIT
Ok, so some down-voting doubters, for some reason, went all weird on my question. So.. for the doubters, this is what how you do it:
List<FBWeird> entities = (List<FBWeird>)Newtonsoft.Json.JsonConvert.DeserializeObject(fbResults.ToString(), typeof(List<FBWeird>));
foreach (FBWeird obj in entities)
{
thisLikeCount = obj.like_count;
}
Output that however you want and it works awesome.
It appears that you're using the Facebook C# SDK. The SDK has two solutions in it - one for 4.0 and one for 3.5. Load the 3.5 solution and compile it and use that DLL instead. Is that what you did to fix it?

Resources