3

I created a DLL project targeting .net standard 2.0.

With NuGet I added a reference to Microfosft.AspNetCore.Http. (2.2.2)

I created this class:

using System;
using Microsoft.AspNetCore.Http;

namespace netstdlib
{
   public class Class1
   {
      public IResult DoGet()
      {
         return null;
      }
   }
}

When I build I get

Build started...
1>------ Build started: Project: netstdlib, Configuration: Debug Any CPU ------
1>D:\PROJECTS\experiment\CS framework test\netstdlib\Class1.cs(10,25,10,32): error CS0246: 
  The type or namespace name 'IResult' could not be found (are you missing a using 
  directive or an assembly reference?)
1>Done building project "netstdlib.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========

It seems to me it should find IResult in the library I'm using. What's wrong?

Alan Baljeu
  • 2,383
  • 4
  • 25
  • 40

2 Answers2

3

The IResult interface in the Microsoft.AspNetCore.Http namespace was added in ASP.NET Core 6, so you need to update if you want to use it.

See documentation: IResult Interface.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • This is not a question of Update. Standard is required for a library that's used by both Framework and Core. I need an alternative. – Alan Baljeu May 12 '22 at 12:58
  • never head of IActionResult. I assumed there was something pre-6 but I couldn't find it. – Alan Baljeu May 12 '22 at 13:06
  • Trying to learn the framework to build a library that provides app-specific HTTP services that is consumable by Framework and Core environments. I only started working Http with .net6 and I needed to make some code available to a .net framework project. – Alan Baljeu May 12 '22 at 13:08
  • Then you should be interested in knowing that there is **no way** to share HTTP methods between ASP.NET Framework and ASP.NET Core - read on: https://stackoverflow.com/questions/47357689/httpcontext-in-net-standard-library/47357919#47357919 – Camilo Terevinto May 12 '22 at 13:12
  • Oh thank you very much for that pointer. That is a huge change in direction for me. – Alan Baljeu May 12 '22 at 13:17
0

Thanks to Camilo for pointing out why IResult can't work. I did find a way that will work:

HttpResponseMessage as produced by HttpClient.GetAsync is usable in .net core. Whether or not these classes are usable in .net framework I didn't try, but I can use HttpResponseMessage to extract data in a Standard dll, and return that data to a .net framework project.

Alan Baljeu
  • 2,383
  • 4
  • 25
  • 40