Repository navigation
Closed
Labels
Description
Describe the bug 🐞
The project is ASP.NET Core Web API that uses Refit packages (Refit 7.2.0, Refit.HttpClientFactory 7.2.0, Refit.Newtonsoft.Json 7.2.0). It contacts 3rd party resource JSONPlaceholder via HTTP.
The interface IBlogApi lists several methods, all of them are annotated by appropriate Refit attributes.
public interface IBlogApi
{
[Get("/posts/{id}")]
Task<Post> GetPostAsync(int id);
[Get("/posts")]
Task<List<Post>> GetPostsAsync();
[Post("/posts")]
Task<Post> CreatePostAsync([Body] Post post);
[Put("/posts/{id}")]
Task<Post> UpdatePostAsync(int id, [Body] Post post);
[Delete("/posts/{id}")]
Task DeletePostAsync(int id);
[Get("/posts")]
Task<List<Post>> GetPostsAsync([Query] PostQueryParameters parameters);
}
The project uses source-generated implementations of these methods to provide various routes. When "GET /posts/1" query is performed, the following exception is thrown:
System.InvalidOperationException: IBlogApi 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.
at Refit.RestService.GetGeneratedType(Type refitInterfaceType) in c:\temp\releaser\refit\Refit\RestService.cs:line 188
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Refit.RestService.For(Type refitInterfaceType, HttpClient client, IRequestBuilder builder) in c:\temp\releaser\refit\Refit\RestService.cs:line 79
at Refit.RestService.For[T](HttpClient client, IRequestBuilder`1 builder) in c:\temp\releaser\refit\Refit\RestService.cs:line 19
at Refit.HttpClientFactoryExtensions.<>c__2`1.<AddRefitClient>b__2_3(HttpClient client, IServiceProvider serviceProvider) in c:\temp\releaser\refit\Refit.HttpClientFactory\HttpClientFactoryExtensions.cs:line 87
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass2_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at lambda_method2(Closure, Object, HttpContext)
at Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
The result is similar for other queries and commands.
Step to reproduce
- Clone linked reproduction repository
- Launch the project in Debug mode
- Perform query: GET /posts/1
- Get error described
Reproduction repository
Expected behavior
The project should return OK response with a body similar to this:
{
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto",
"userId": 1
}
Screenshots 🖼️
No response
IDE
Rider Windows
Operating system
Windows
Version
11 23H2
Device
No response
Refit Version
7.2.0
Additional information ℹ️
Current workaround: downgrade Refit packages from version 7.2.0 to 7.1.2.
Reacted by Dan Lumpp, Niels Morf, Humberto Aicardi, Fábio Gomes, Tim M and Kai-Rune Slettemoen
Activity
freenetbrasil commentedon Sep 18, 2024
Same here; I had to downgrade to 7.1.2
TimothyMakkison commentedon Sep 18, 2024
Thanks for the example repository, this looks pretty severe. I don't see any implementations of
IBlogApior evenpartial class Generatedbeing created. Looks like the source generator isn't running.@ChrisPulman any idea what has changed since 7.1.2 to cause this?
ChrisPulman commentedon Sep 18, 2024
ChrisPulman commentedon Sep 18, 2024
This was run using VS2022 V17.11.3, sorry, I don't have Rider to test with.
ChrisPulman commentedon Sep 18, 2024
@TimothyMakkison Do you have Rider? If so, does this issue occur when you run it?
TimothyMakkison commentedon Sep 18, 2024
I think the issue is 29e0e1c. Looks like
Microsoft.CodeAnalysis.CSharpwas mistakenly updated.Yeah, I have rider and I get the same error message.
ChrisPulman commentedon Sep 18, 2024
@TimothyMakkison Thank you Tim, strange that it only affects Rider.
TimothyMakkison commentedon Sep 18, 2024
I'm guessing you are on the latest version of Visual studio where they support
Microsoft.CodeAnalysis.CSharp4.11.0. Rider might still be on 4.10.0 hence why nothing is generated.flojon commentedon Sep 18, 2024
ChrisPulman commentedon Sep 19, 2024
Please update to 7.2.1 this issue should be resolved, thank you
flojon commentedon Sep 19, 2024
7.2.1 works good for me. Thanks!
aywee26 commentedon Sep 19, 2024
Weird development on the issue:
Tried to test the issue of Refit 7.2.0 further. I had Visual Studio installed, not the most recent version, at least 3 months old. Tried to replicate the issue - success, same exception is thrown.
So I updated the IDE via Visual Studio installer, to version 17.11.4. And now, whether I use VS or Rider, project builds, runs and the issue cannot be replicated.
Tried to use different versions of Rider, installed via JetBrains Toolbox (specifically 2024.2.4, 2024.1.6 and 2023.3.6), couldn't replicate the issue.
Anyway, Refit 7.2.1 also works fine, with no issues.
github-actions commentedon Oct 4, 2024
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.