Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.MissingMethodException when ITwilioRestClient created via DI #768

Open
keltex opened this issue Nov 7, 2024 · 12 comments
Open

System.MissingMethodException when ITwilioRestClient created via DI #768

keltex opened this issue Nov 7, 2024 · 12 comments
Assignees

Comments

@keltex
Copy link

keltex commented Nov 7, 2024

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:

  • twilio-csharp version: 7.6.0
  • csharp version: 7
@Swimburger
Copy link
Contributor

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 AsabuHere self-assigned this Nov 26, 2024
@AsabuHere
Copy link
Contributor

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

@Swimburger
Copy link
Contributor

Swimburger commented Nov 26, 2024

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

@Daniel15
Copy link

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

@AsabuHere
Copy link
Contributor

This issue is fixed in the codebase and will be part of next release

@ltctech
Copy link

ltctech commented Dec 6, 2024

@Swimburger @AsabuHere

I updated to Twilio 7.8.0 and Twilio.AspNet.Core 8.1.0 today. Still getting an error:

System.MissingMethodException: Method not found: 'Void Twilio.Clients.TwilioRestClient..ctor(System.String, System.String, System.String, System.String, Twilio.Http.HttpClient, System.String, Twilio.AuthStrategies.AuthStrategy)'.
   at Twilio.AspNet.Core.TwilioClientDependencyInjectionExtensions.CreateTwilioClient(IServiceProvider provider)

Reverting to Twilio.AspNet.Core 8.0.2 fixes it. Seems both libraries were modified to support the other and now they're again no longer compatible.

@Daniel15
Copy link

Daniel15 commented Dec 6, 2024 via email

@Swimburger
Copy link
Contributor

Swimburger commented Dec 6, 2024

Why aren't these two libraries in the same repo and released concurrently? It's not great to have releases that are incompatible with each other like this.

On December 5, 2024 6:02:44 PM PST, ltctech @.> wrote: @Swimburger @AsabuHere I updated to Twilio 7.8.0 and Twilio.AspNet.Core 8.1.0 today. Still getting an error: System.MissingMethodException: Method not found: 'Void Twilio.Clients.TwilioRestClient..ctor(System.String, System.String, System.String, System.String, Twilio.Http.HttpClient, System.String, Twilio.AuthStrategies.AuthStrategy)'. at Twilio.AspNet.Core.TwilioClientDependencyInjectionExtensions.CreateTwilioClient(IServiceProvider provider) Reverting to Twilio.AspNet.Core 8.0.2 fixes it. Seems both libraries were modified to support the other and now they're again no longer compatible. -- Reply to this email directly or view it on GitHub: #768 (comment) You are receiving this because you commented. Message ID: @.>

Twilio.AspNet is a community project, not officially supported by Twilio.

Regardless, the change that was just made in this repo was another breaking change because the position of the authstrategy parameter was moved to the third position (source).

@Swimburger
Copy link
Contributor

Twilio.AspNet has been updated to use the latest version of Twilio C# helper library again.

@williamdenton
Copy link

williamdenton commented Dec 8, 2024

I have just been caught by this too - i used the latest libraries for both projects are they are not compatible. (7.2.2 and 8.1.0)

Changing the parameter order is a semver breaking change.

@williamdenton
Copy link

It looks like 8.1.1 fixes this, but there is no release notes to this effect

I would still advise you add the constructor back to this library to make it backwards compatible. But you are going to have to leave the new one there too. When you next do a major release you can tidy it up. Judging by nuget download counts this hasn't affected may users yet. You can still fix it before more and more people come here to complain.

image
image

@sbansla
Copy link
Contributor

sbansla commented Feb 20, 2025

I will check this shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants