Serverless Azure SignalR service & .NetFramework 4.7.1 (Unity app) - signalr.client

Is it possible to listen for the events from Serverless Azure SignalR service from .NetFramework 4.7.1 (Unity) app?
I have implemented the solution which works with javascript client and .net Core 3.1 client, but cannot get the .NetFramework 4.7.1 (Unity app) client to work. I am trying to use the same libraries as with the .Net Core 3.1 client. That is: "Microsoft.AspNetCore.SignalR.Client" version 5.0.2 with its dependencies. But I am getting different kinds of errors from the libraries.
When I am missing dependencies such as System.Text.Json I get an error
Unloading broken assembly Assets/Plugins/Microsoft.AspNetCore.SignalR.Common.dll, this assembly can cause crashes in the runtime
When I add the dependency the error is:
TypeLoadException: Could not resolve type with token 01000066 (from typeref, class/assembly System.Text.Json.Serialization.JsonIgnoreCondition, System.Text.Json, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51)
Microsoft.AspNetCore.SignalR.JsonHubProtocolOptions..ctor () (at <c72a5d3426db4d1989e41390e5494e1a>:0)
Is it supposed to work like that, or am I banging my head to the stone. I am not familiar with the C# library / runtime stuff.

Related

Project is targeting runtime 'win7-x64' but did not resolve any runtime-specific packages for the 'Microsoft.NETCore.App' package

I am trying to deploy stateless micro service application into service fabric but I get this error as soon as I start the deployment.
Project is targeting runtime 'win7-x64' but did not resolve any runtime-specific packages for the 'Microsoft.NETCore.App' package. This runtime may not be supported by .NET Core.
How to fix this ?
If you're unable to upgrade to .NET Core 3.1, you can suppress this error by adding this inside a <PropertyGroup> in your project file:
<EnsureNETCoreAppRuntime>false</EnsureNETCoreAppRuntime>
The error is a design-time error and won't cause a runtime failure.
If you create your stateless micro service application on VS2019, you should note that Net Core <=3.0 is not supported by Stateless project.
So you should target your project framework to at least Net Core 3.1.
Right-click on your project Properties-->Application-->change target framework version to net core 3.1.
If I target project into net core 2.2, the error will happen.
Note that, you should make sure that your target framework version of the pubxml file is the same of your project target framework version.

What Microsoft.AstNetCore.SpaServices.Extension version has UseHsts method or alternative method that is compatible with .Net Framework 4.61?

I have a .Net Core 3.1 web application. Since I have to communicate to a legacy service using .Net Remoting, I decided to change the TargetFramework to 4.61. This has caused error with (IApplicationBuilder)app.UseHSTS(). So, I updated my referenced version of Microsoft.AspNetCore.SpaServices.Extension to 2.2.0. However, UseHSTS is not available with it. Is there an alternative solution?

System.Web.ApplicationServices in .NET Core 2

I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution
package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.
The app is also throwing this exception below when I call code in one of the custom packages
System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified
Is there any way around this other than re-writing the code in my web Api?
No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.
Long and short, if there's any dependency on System.Web at all, you can't use it.

Could not load file or assembly 'AutoMapper' in .net project

Could not load file or assembly 'AutoMapper, Version=6.1.1.0,
Culture=neutral, PublicKeyToken=be96cd2c38ef1005' or one of its
dependencies. The system cannot find the file specified.
I have two projects: Azure Function Project and Library project. The library project is where the database tables, context defined in it which running .Net Core 2.0 whereas the Azure Function Project run on .Net Framework 4.6.1.
The error occurred when calling the
db.ExecuteProcedureQuery<ApiAttendanceModel>(StoredProcedureName.Sp_GetAttendanceByAttendanceId, out error, parameterList).SingleOrDefault();
Does anyone know what the issue is?
Inside the azure function (trigger by queue), tried to connect to azure table in the code. It fired and exception. So I changed the project back to .net standard 4.6.1
AFAIK, Microsoft.NET.Sdk.Functions depends on Microsoft.Azure.WebJobs which would depends on WindowsAzure.Storage.
Per my test, I could leverage the client SDK to work with Azure Table storage under my Azure Functions v2.
If your Azure Function targets .NET Framework v4.6.1, after you references the Net Core 2.0 class library, your Azure Function project would retrieve the compile errors as follows:
For your scenario, I would recommend you create a class library targets the .Net Standard that allows your library to be called by your Azure Functions v1 (.NET Framework) or Azure Functions v2 (.NET Core). Details you could follow Building a .NET Standard class library with C#.
Moreover, I just created my .Net Standard 1.3 class library to test this issue. You need to choose which .Net Standard version to be targeted, details you could follow here.

Referencing .NET 4.7.1 library using Azure Storage from ASP.NET Core 2 MVC App

In my solution I have an ASP.NET Core 2 MVC app using Razor pages, a Web API 2 app and a .NET 4.7.1 class library containing services and their definitions that use Azure Table Storage from the Azure Storage NuGet (v8.7.0). I'm using autofac for dependency injection.
I have hooked up both my web apps to use classes from my library using Autofac's dependency injection. The Web API app works fine but the Core app doesn't. When I build without installing the Azure Storage NuGet package into the Core app I get the following error:
X.Library' with identity 'X.Library, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' uses 'Microsoft.WindowsAzure.Storage,
Version=8.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
which has a higher version than referenced assembly
'Microsoft.WindowsAzure.Storage' with identity
'Microsoft.WindowsAzure.Storage, Version=8.1.4.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
Which leads me to believe that ASP.NET Core 2 apps have Azure Storage pre-installed - I can't find any reference to it in the project though! Weird.
So I have tried to fixed this by installing the Azure Storage (v8.7.0) package which matches the version installed in the library I am using into my Core app. The app now builds and my dependencies are injected but when I try to use them I get MissingMethodExceptions for the methods CreateIfNotExists and CreateQuery. While my Web API app can query Azure Table Service my Core app can't use the same methods to do so.
After some research it seems that the ASP.NET Core implementation of the Azure Storage library has removed some synchronous methods and at runtime it uses this version rather than the .NET Framework compatible version my library references.
Is there any way to remove Azure Storage from the ASP.NET Core 2 app? Is it preinstalled, as I suspect?
I guess the easiest way to fix it is to use methods that are present in the Framework and Core implementations, is this how you'd fix it?
I found a solution to this problem with the help of this blog post: https://weblog.west-wind.com/posts/2017/Jun/22/MultiTargeting-and-Porting-a-NET-Library-to-NET-Core-20
The post talks you through the process of porting a .Net Library to a .Net Standard library that targets multiple runtime versions. This turns out to be exactly what I needed to do.
I took my service that I had written in .Net framework 4.5.1 and copied the files to a new .Net Standard library I created. I then changed the target frameworks to support multiple runtime versions manually (you can't do this using the Visual Studio UI at time of writing). For my purposes I used the following to support .Net Core 2, .Net Standard and .Net 4.7.0:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.0;netstandard2.0;net47</TargetFrameworks>
</PropertyGroup>
The framework you write first is the one that is targeted but I found that Visual Studio gave me errors for methods that weren't available in all versions of the Azure Storage library so I was able to write a service which worked on all three without writing any runtime-specific code.