How to generate service reference for .netstandard 2 - asp.net-core

We're migrating our codebase from .net framework to .net 7. To do so, we're converting our infrastructure projects (domain objects, business layer, data layer) to .netstandard 2 so that we can use it in both the old and new versions of the front end web applications while they're being migrated.
I need to generate service references in one of the .netstandard projects but when I try to add a new service under Manage Connected Services, I get the following error.
MSBuild version 17.4.0+18d5aef85 for .NET
C:\Users\geoff\.nuget\packages\system.runtime.compilerservices.unsafe\6.0.0\buildTransitive\netcoreapp2.0\System.Runtime.CompilerServices.Unsafe.targets(4,5): error : System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0. Consider updating your TargetFramework to netcoreapp3.1 or later. [C:\Users\geoff\AppData\Local\Temp\WCFConnectedService\2023_Jan_31_15_49_26\svcutil_bootstrap\SvcutilBootstrapper\SvcutilBootstrapper.csproj]
Build FAILED.
C:\Users\geoff\.nuget\packages\system.runtime.compilerservices.unsafe\6.0.0\buildTransitive\netcoreapp2.0\System.Runtime.CompilerServices.Unsafe.targets(4,5): error : System.Runtime.CompilerServices.Unsafe doesn't support netcoreapp2.0. Consider updating your TargetFramework to netcoreapp3.1 or later. [C:\Users\geoff\AppData\Local\Temp\WCFConnectedService\2023_Jan_31_15_49_26\svcutil_bootstrap\SvcutilBootstrapper\SvcutilBootstrapper.csproj]
0 Warning(s)
1 Error(s)
Any idea how I can get this working with the current .netstandard 2 setup?

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.

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.

fully compatible powerbi.api package with aspnetcore?

i was able to get the sample asp.net embedded powerbi to work with my reports
now i have to migrate it aspnetcore
i was hopeful when i saw this post - seeing that someone was able to get it done
Embed Power BI Report In ASP.Net Core Website
so i:
started a new project with the aspnetcore
installed the powerbi package
now when compiling im getting this warning:
Package 'Microsoft.PowerBI.Api 2.0.11' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
i searched and couldnt find a powerbi package that was specific to aspnetcore
is there one? will there be a conflict crossing cores? or does it not matter?
UPDATE:
4.6.1 powerbi package does indeed work with aspnetcore 2
but looking forward to a powerbi package specifically coded for core
As you can see this is just a warning, not an error. That warning appears because .NET Core 2.0 applications can use some Nuget packages which target .NET Framework 4.6.1 (or less). However, this inclusion might fail if the referenced .NET 4.x package contains some API not included into .NET Core/.NET Standard 2.0
So, my advice - try to run your application. If it works well at the first glance - then, most probably that PowerBI package does not contain any not supported APIs and will work well further. If it fails right at start - then you will need to wait for the release of the new version of that package which targets .NET Standard 2.0.

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.

ASP.NET Core publish fails when referencing other project

I'm evaluating Visual Studio 2017 RC for our next project and ran into some issues. For the real project I have a web frontend and a Windows service which use the same shared library for database stuff (and more). All projects are based on the classic .NET Framework 4.6.2. Deployment will be on an on-premise Windows Server.
I created a minimal example as follows:
Create a solution with ASP.NET Core (.NET Framework) project MyTest.Web.
Add classic desktop class library MyTest.Shared.
Reference MyTest.Shared in projects MyTest.Web.
Add code reference to MyTest.Shared by adding something like var c = new MyTest.Shared.Class1() to the web project.
Developing works like a charm: Building, starting and debugging the project is no problem. But I just can't publish the project. If I use the Publish entry from the project's context menu, I get the following error:
Program.cs(7,21): Error CS0234: The type or namespace name 'Shared' does not exist in the namespace 'MyTest' (are you missing an assembly reference?)
According to the full console output, there is another build using csc, but apparently it doesn't know about my shared project.
If I use dotnet publish -c Release to publish the project, I get the following error:
error MSB4057: The target "GetCopyToPublishDirectoryItems" does not exist in the project.
So in this case, the library seems to be referenced and built correctly, but there is another error. (full console output)
I think referencing other projects is something very essential, so why doesn't it work? Did I forget something?
My .NET CLI version is 1.0.0-preview3-004056.