reactiveui / refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
https://reactiveui.github.io/refit/
MIT License
8.62k stars 746 forks source link

[BUG] Still doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project #1080

Closed sevencat closed 3 years ago

sevencat commented 3 years ago

version:Refit.6.0.15.nupkg netframework:4.8

using System.Threading.Tasks;
using Refit;

namespace SnapOffline
{
    public interface IWtApi
    {
        [Post("/xx/showreport.asp")]
        Task<ResponseShowReport> ShowReport([Body(BodySerializationMethod.UrlEncoded)]
            RequestShowReport req);
    }
}
System.InvalidOperationException: IWtApi doesn't look like a Refit interface. Make sure it has at least one method with a Refit HTTP method attribute and Refit is installed in the project.
   在 Refit.RestService.GetGeneratedType(Type refitInterfaceType) 位置 /_/Refit/RestService.cs:行号 100
   在 Refit.RestService.For(Type refitInterfaceType, HttpClient client, IRequestBuilder builder) 位置 /_/Refit/RestService.cs:行号 36
   在 Refit.RestService.For[T](HttpClient client, IRequestBuilder`1 builder) 位置 /_/Refit/RestService.cs:行号 13
   在 Refit.RestService.For[T](HttpClient client, RefitSettings settings) 位置 /_/Refit/RestService.cs:行号 20
   在 Refit.RestService.For[T](HttpClient client) 位置 /_/Refit/RestService.cs:行号 23
   在 SnapOffline.Program.Main(String[] args) 位置 E:\work\med\MedSnap\weitong\Snap\SnapOffline\Program.cs:行号 23
clairernovotny commented 3 years ago

How are you building this project? What version of Visual Studio/MSBuild? Do you have a minimal repro solution?

t1g0rs commented 3 years ago

I've same problem. After upgrading from version 5.2.4 I've noticed build targets for old version were removed from csproj, but no new were added. VS 2019. Target framework 4.8.

automachina commented 3 years ago

I have the same issue. Just happened after updating Refit to version 6.0.15 from 5.2.1 I've attached a Xamarin Workbook file that reproduces the issue and mimics the method that's throwing the method.

RefitServiceException

Xamarin Workbook Details

Xamarin Workbooks

Detail Value
Version 1.5.0
Git Branch 1.5-release
Git Hash 11f83dc
VSTS Definition Workbooks & Inspector (Mac)

System Info

Component Value
macOS Version 10.15.7 (Build 19H524) (64-bit)
CPU Cores 4 / 4
Physical Memory 16 GB

System-Installed Software

Component Version
Mono 6.12.0.122
Xamarin Mac 7.4.0.4
Xamarin iOS 14.10.0.4
Xamarin Android 11.1.0-26
Visual Studio 8.8.9.10 (808090010)

RefitServiceException.workbook.txt

clairernovotny commented 3 years ago

It appears that Xamarin Workbooks doesn't support Source Generators yet. That's likely a different issue than the first one.

automachina commented 3 years ago

Oh okay, sorry about that. I had to walk the version back to 5.2.4 to get it to run in my Xamarin project.

=== Visual Studio Community 2019 for Mac ===

Version 8.8.9 (build 10) Installation UUID: 35fb9683-7640-4056-9f83-040b50bd7056 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000122

=== Mono Framework MDK ===

Runtime: Mono 6.12.0.122 (2020-02/c621c35ffa0) (64-bit) Package version: 612000122

=== Roslyn (Language Service) ===

3.8.0-5.20519.18+4c195c3ac1974edcefa76774d7a59a2350ec55fa

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.103/Sdks SDK Versions: 5.0.103 5.0.102 5.0.101 5.0.100 3.1.406 3.1.405 3.1.404 3.1.403 3.1.402 3.1.401 3.1.302 3.1.301 3.1.300 3.1.202 3.1.200 3.1.102 3.1.101 3.1.100 3.0.100 2.1.701 2.1.503 MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 5.0.3 5.0.2 5.0.1 5.0.0 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.0 2.1.23 2.1.22 2.1.21 2.1.20 2.1.19 2.1.18 2.1.17 2.1.16 2.1.15 2.1.14 2.1.13 2.1.12 2.1.7 2.0.9

=== .NET Core 3.1 SDK ===

SDK: 3.1.406

=== Xamarin.Profiler ===

Version: 1.6.12.29 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.1.0.26 (Visual Studio Community) Commit: xamarin-android/d16-8/a36ce73 Android SDK: /Users/gaelan/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.5 SDK Build Tools Version: 30.0.3

Build Information: Mono: 5e9cb6d Java.Interop: xamarin/java.interop/d16-8@79d9533 ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-8@2fb1cbc

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/gaelan/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.8.0.32 Hash: 01a7774 Branch: remotes/origin/d16-8 Build date: 2021-01-14 00:34:58 UTC

=== Android Device Manager ===

Version: 16.8.0.46 Hash: 0a81419 Branch: remotes/origin/d16-8 Build date: 2021-01-14 00:35:22 UTC

=== Xamarin Designer ===

Version: 16.8.0.510 Hash: 44e3f3ce9 Branch: remotes/origin/d16-8 Build date: 2020-12-10 00:06:14 UTC

=== Apple Developer Tools ===

Xcode 12.4 (17801) Build 12D4e

=== Xamarin.Mac ===

Version: 7.4.0.4 (Visual Studio Community) Hash: 5a05865f6 Branch: xcode12.4 Build date: 2021-01-28 02:30:22-0500

=== Xamarin.iOS ===

Version: 14.10.0.4 (Visual Studio Community) Hash: 5a05865f6 Branch: xcode12.4 Build date: 2021-01-28 02:30:23-0500

=== Build Information ===

Release ID: 808090010 Git revision: 0061f975f58a5dba53e339f116371f4853edeb75 Build date: 2021-02-11 11:16:18-05 Build branch: release-8.8 Xamarin extensions: 0061f975f58a5dba53e339f116371f4853edeb75

=== Operating System ===

Mac OS X 10.15.7 Darwin 19.6.0 Darwin Kernel Version 19.6.0 Tue Jan 12 22:13:05 PST 2021 root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

.NET Core support for Mono.Debugging 8.0.5 Android Signature Tool 2.2.0

GitHub
xamarin/AndroidDesigner.EPL
Contribute to xamarin/AndroidDesigner.EPL development by creating an account on GitHub.
namilkimfree commented 3 years ago

I've same problem.
refit version 6.0.1 and 6.0.15 refit.Newtonsoftjson 6.0.1 VS 2019, Target framework 4.6.1

`

        [Headers("Content-Type: application/json")]
        public interface ILabTicketAPI
        {
             [Post("/regist/{parkId}/{ymd}")]
             Task<string> Test(string parkId, [AliasAs("ymd")] string today);
         }

         var clinet = new HttpClient();
        clinet.BaseAddress = new Uri(setting.BaseUrl);

        var refitSettings = new RefitSettings()
        {
            ContentSerializer = new NewtonsoftJsonContentSerializer(
                new JsonSerializerSettings()
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver(),
                    DefaultValueHandling = DefaultValueHandling.Ignore,
                    NullValueHandling = NullValueHandling.Ignore,
                })
        };

        labTicketApi = RestService.For<ILabTicketAPI>(clinet, refitSettings);  ---> Throw Exception

`

@clairernovotny

mekangarayev commented 3 years ago

I have the same problem i updated to 6.0.15 from 5.2.4 framework : 4.7.2

My Interface public interface IInvoiceApi { [Refit.Post("/{mainalias}")] Task Upload_InvLines([Body] List lines, [Header("token")] string authorization,string mainalias); }

Implementation

private async Task ExecuteApiImpl() { try { var s = SqlGenerator.GetInvoiceDetails(DateTime.Today, DateTime.Today, "8"); var data = DataAccess.getExecuteSqlAsList(s); var onlineapi = RestService.For(akh_api_base_address);//====>throws exception await onlineapi.Upload_InvLines(data, akh_api_token, akh_api_aliaspath).ConfigureAwait(true); } catch (Exception ex) { var exmes = ex.Message; } return Unit.Default; }

clairernovotny commented 3 years ago

@mekangarayev @namilkimfree As this is related to Source Generators, I need more information about how the project is built, not just the interface itself.

What version of VS are you using and how are you building the project when you see this error? If you're building on the command line, what do you see with msbuild /version?

namilkimfree commented 3 years ago

@clairernovotny VS version = Version 16.8.4 msbuild / version 15.0 refit version 6.0.1 and 6.0.15 refit.Newtonsoftjson 6.0.1 VS 2019, Target framework 4.6.1

clairernovotny commented 3 years ago

How is msbuild 15.0 is being used? How is that being located? That's the VS 2017 version of MSBuild.

namilkimfree commented 3 years ago

It is Programfiles(x86)₩msbuild₩15.0

clairernovotny commented 3 years ago

Understood, but how are you getting that? Are you calling a "Developer Command Prompt"? What is putting that in the path?

MSBuild shouldn't generally be in the path like that as it's pulling in that older version and will cause you other issues too.

namilkimfree commented 3 years ago

.Net Framework winforms version .Net Framework 4.6.1 "Developer Command Prompt" path is C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools

.csproj value is

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{DE3379A5-7641-42B7-89DA-1D285137640D}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>RefitNewVersionTest</RootNamespace>
    <AssemblyName>RefitNewVersionTest</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <StartupObject>RefitNewVersionTest.Program</StartupObject>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
    </Reference>
    <Reference Include="Refit, Version=6.0.0.0, Culture=neutral, PublicKeyToken=2f9b1262776509f5, processorArchitecture=MSIL">
      <HintPath>..\packages\Refit.6.0.15\lib\net461\Refit.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
    </Reference>
    <Reference Include="System.Core" />
    <Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
    </Reference>
    <Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
    </Reference>
    <Reference Include="System.Net.Http.Json, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Net.Http.Json.5.0.0\lib\net461\System.Net.Http.Json.dll</HintPath>
    </Reference>
    <Reference Include="System.Numerics" />
    <Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
    </Reference>
    <Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Cryptography.Algorithms, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
    </Reference>
    <Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
    </Reference>
    <Reference Include="System.Text.Encodings.Web, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Text.Encodings.Web.5.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
    </Reference>
    <Reference Include="System.Text.Json, Version=5.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Text.Json.5.0.1\lib\net461\System.Text.Json.dll</HintPath>
    </Reference>
    <Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
    </Reference>
    <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
      <HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
    </Reference>
    <Reference Include="System.Web" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="IGitHubApi.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="User.cs" />
    <EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
    </EmbeddedResource>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <None Include="packages.config" />
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
      <Visible>False</Visible>
      <ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
      <Install>true</Install>
    </BootstrapperPackage>
    <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
      <Visible>False</Visible>
      <ProductName>.NET Framework 3.5 SP1</ProductName>
      <Install>false</Install>
    </BootstrapperPackage>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

.NET 5.0 Winforms version .NET(5) it is success , don't throw exception.
.csproj value is

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Refit" Version="6.0.15" />
  </ItemGroup>
</Project>
clairernovotny commented 3 years ago

Thanks. I'll look into the issue with the Roslyn team but my first guess is that there's an issue with Source Generators using older packages.config nuget format. There's no reason to use that anymore -- can you right click the packages.config file in VS and select the "convert to PackageReference" option and try again? I believe that context menu option should be there.

namilkimfree commented 3 years ago

@clairernovotny thank you

.Net Framework 4.6.1 is migrating to PackageReference, so it does not throw an exception.

it's done!

mekangarayev commented 3 years ago

Yes, perfect, it works!

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.