How to use SignalR with aspnetcore 2.0.0 preview - asp.net-core-mvc

I am trying to use SignalR with aspnetcore 2.0.0 preview. The preview version is supposed to have support for signalR as per the release notes and I can add references to the "Microsoft.aspnetcoreSignalR" package.
However, I am unable to find the MapSignalR extension method or something like useSignalR() on the IApplicationBuilder.
Googling around for this gives lots of examples of the UseAppBuilder extension method. However, I still get stuck at MapSignalR with the below code:
using Microsoft.AspNetCore.Builder;
using Microsoft.Owin.Mapping;
using Microsoft.Owin.Helpers;
using Microsoft.Owin.Extensions;
using Microsoft.Owin.Builder;
using Owin;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace MyNamespace
{
using AppFunc = Func<IDictionary<string, object>, Task>;
public static class SignalRExtensions
{
public static IApplicationBuilder UseAppBuilder(this IApplicationBuilder app, Action<IAppBuilder> configure)
{
app.UseOwin(addToPipeline =>
{
addToPipeline(next =>
{
var appBuilder = new AppBuilder();
appBuilder.Properties["builder.DefaultApp"] = next;
configure(appBuilder);
return appBuilder.Build<AppFunc>();
});
});
return app;
}
public static void UseSignalR2(this IApplicationBuilder app)
{
app.UseAppBuilder(appBuilder => appBuilder.MapSignalR());
}
}
}
This is unable to find the MapSignalR extension method. Any thoughts on if I can find this some nuget package that will work with aspnetcore? Or is there a different mechanism to initialize signalR with aspnetcore 2.0.0 preview?
I am using visual studio 2017 preview 15.3 with .Net core 2.0 preview installed.

I basically hada the wrong set of nugget references. If I only have aspnetcore 2.0.0 preview 1 and the corresponding Microsoft.aspnetcore.signalR 1.0.0 preview package, there is already a UseSignalR() method available as an extension method for IApplicationBuilder and we don't need any of the above code.

Related

IApplicationBuilder does not includes a definition for UseHealthChecks

As suggested at the tutorial for kubernetes health check I like to implement the health chack at my .NET Core WebApi at class startup.cs at method Configure.
But the method .UseHealthCheck() is unknown.
I don't know what creates this problem. I guess all usings are there?!?
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseHealthChecks("/health");
app.Run(async (context) =>
{
await context.Response.WriteAsync(
"Navigate to /health to see the health status.");
});
here the using:
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Identity.Client;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
How to fix this problem?
Thanks for your help!
Frank
Thanks mxmissile!
I add the NuGet package
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
and there for also and first
Microsoft.AspNetCore.Http.Features 2.2.0
Microsoft.AspNetCore.Http.Abstractions 2.2.0
Microsoft.Net.Http.headers 2.2.0
Now the method is known.
I've found you only need to install these two
Microsoft.AspNetCore.Diagnostics.HealthChecks 2.2.0
Microsoft.Extensions.Diagnostics.HealthChecks 2.2.0

MvvmCross ShowViewModel method missing

I followed the documentation on testing on the MvvmCross website. I'am able to register my mock dispatcher and everything works except when any of my view models executes ShowViewModel. This gives me a System.MissingMethodException.
My test class is a class library (.Net 4.5).
I have a WPF application, and everything works fine in there. But for some reason, my test class library gives me this problem. I've removed/reinstalled all NuGet packages, unchecked/checked all references to my PCL where the view models I'm testing are located.
1) Why am I getting this exception?
1.1) Could it be some dll that I'm missing?
2) Where is the actual concrete definition for ShowViewModel? The only reference I can find is in MxvNavigationObject, but that's an abstract class.
Is your Viewmodel class (where I hope you are trying to call it) inheriting from MvxViewModel? as that is where the ShowViewModel method is (via MvxNavigatingObject)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MvvmCross.Core.ViewModels;
namespace App1.ViewModels
{
public class MainViewModel : MvxViewModel
{
public MainViewModel()
{
ShowViewModel(typeof(SecondViewModel));
}
}
}

MVC Console app in VS 2017 - unable to serve razor views

I have created basic MVC application in asp.net core with Visual Studio 2017.
I got an error when trying to render index.cshtml
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
Generated Code
One or more compilation references are missing. Possible causes
include a missing 'preserveCompilationContext' property under
'buildOptions' in the application's project.json.
The type or namespace name 'System' could not be found (are you
missing a using directive or an assembly reference?)
+
using System;
...
My whole console application is as short as it can be:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var host = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
app.UseMvc();
}
}
public class HomeController : Controller
{
[HttpGet("/")]
public ActionResult Index()
{
ViewBag.Message = "Hello world!";
ViewBag.Time = DateTime.Now;
return View();
}
}
}
Structure of my "project"
View
It's funny because the error tells me that I have to change something in project.json, but since Visual Studio 2017 there is no project.json anymore.
My view is in fact simple static html file and does not require any references to models or anything. But errors are complaining about missing types:
I tried to compare my project to web application template but I havent found what's causing razor views not to build in console application.
What am I missing here?
Try adding
<PropertyGroup>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
to your csproj. And to avoid such mistakes next time, please use the ASP.NET Core templates you can find when you create a new project. They have the necessary stuff and commonly used packages added to it's csproj.
There is a different SDK to use.
Console Apps use: Microsoft.NET.Sdk
Web Apps use: Microsoft.NET.Sdk.Web
This can be updated in your *.csproj

SHA256CryptoServiceProvider not working in Xamarin

I create cross-platform project Xamarin.Forms (shared) in Visual Studio 2015, add one page; and I need SHA256CryptoServiceProvider, but i have a problem:
"Error CS0246: The type or namespace name 'SHA256CryptoServiceProvider' could not be found (are you missing a using directive or an assembly reference?)"
MD5CryptoServiceProvider - working good.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using Xamarin.Forms;
namespace App1
{
public partial class Page1 : ContentPage
{
public Page1 ()
{
InitializeComponent ();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
}
}
}
It is because this class... really doesn't exist. Why? Using Xamarin, you are using portable .NET which lacks some of the full .NET features. I'm afraid you need to use some external libraries like PCLCrypto to fulfill your needs, or implement it by yourself (this is what I've done when I needed hash function in my Xamarin App)

Linq intellisense Missing on EF Object

I'm facing a strange type of issue.
In my VS Solution I have 3 projects.
ASP.Net App
C# Class Library (Used as my DAL and contains a EF .edmx file.
Windows Service App
The ASP.Net App can succesffully access the the EF Model and I can use either classic Linq or Lambda .First() etc. Everything works fine.
On my Windows Service App, I've added a reference to the DAL DLL , but for some reason, the Intellisense does not show up when I type in any code files in the windows service library. Example of my code below :
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace alertservice
{
class AlertPolling
{
dal.applicationEntities ent;
public AlertPolling()
{
ent = new dal.applicationEntities();
ent.Queries. // <--- ZERO INTELLISENSE HAPPENING HERE.
}
public void StartPolling()
{
}
}
}
Thanks guys. I managed to fix the problem by following the comments from flipchart.
I added a reference to System.Data.Entity which fixed it. Intellisense now coming up.

Resources