twilio / twilio-csharp

Twilio C#/.NET Helper Library for .NET6+.
MIT License
677 stars 301 forks source link

System.MissingMethodException when ITwilioRestClient created via DI #768

Open keltex opened 2 weeks ago

keltex commented 2 weeks ago

Issue Summary

This is a dotnetcore application running on dotnet 7. When attempting to instatiate a ITwilioRestClient via dependency injection, I get the following exception:

System.MissingMethodException: 'Method not found: 'Void Twilio.Clients.TwilioRestClient..ctor(System.String, System.String, System.String, System.String, Twilio.Http.HttpClient, System.String)'.'

This is happening on twilio 7.6.0. If I roll back to twilio 7.5.1 the bug does not occur.

Steps to Reproduce

  1. Nuget to install twilio version 7.6.0
  2. Configure twilio in startup.cs
  3. Attempt to instantiate a ITwilioRestClient via DI

Code Snippet

Here's my code to create the service in startup.cs

services.AddTwilioClient(optionsToConfigure =>
{
    auction4.Services.Utility.TwilioUtil.SetOptions(Configuration, optionsToConfigure);
});

Then the exception occurs when my razor page loads:

private readonly ITwilioRestClient _twilioClient;
private readonly IConfiguration _configuration;

public TwilioSendModel(IConfiguration configuration, 
    ITwilioRestClient twilioClient)
{
    _twilioClient = twilioClient;
    _configuration = configuration;
}

Exception/Log

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Void Twilio.Clients.TwilioRestClient..ctor(System.String, System.String, System.String, System.String, Twilio.Http.HttpClient, System.String)'.
  Source=Twilio.AspNet.Core
  StackTrace:
   at Twilio.AspNet.Core.TwilioClientDependencyInjectionExtensions.CreateTwilioClient(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)

Technical details:

Swimburger commented 4 days ago

Changing the signature of a method or constructor is a breaking change. Even if it's a new optional parameter, as you can see above, it requires depending libraries to recompile and release a new version.

@Twilio maintainers, if you add new parameters, provide overloads so the original signature still exists for existing libraries.

AsabuHere commented 1 day ago

@keltex Thank you for raising this issue. Our team is currently looking into this issue and will be prioritised in the current sprint

Swimburger commented 1 day ago

This PR recompiles against your new ctor signature, so it'll work again if merged and released. https://github.com/twilio-labs/twilio-aspnet/pull/141

Daniel15 commented 3 hours ago

I'm hitting the same issue. Reverting to v7.5.1 worked for me too.