以下代码:
using Microsoft.Azure.WebJobs;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
namespace FunctionApp2
{
public static class Function1
{
[FunctionName("Function1")]
[return: TwilioSms(AccountSidSetting = "AccountSidSetting", AuthTokenSetting = "AuthTokenSetting", From = "From")]
public static CreateMessageOptions Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer)
{
var message = new CreateMessageOptions(new PhoneNumber("XXXXX"))
{
Body = $"Hello thanks for your order!"
};
return message;
}
}
}
给出错误:
"Microsoft.Azure.WebJobs.Host: Error indexing method 'Funct
ion1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twilio.Re
st.Api.V2010.Account.CreateMessageOptions&'.
[2018-12-02 18:03:44] Error indexing method 'Function1.Run'
[2018-12-02 18:03:44] Microsoft.Azure.WebJobs.Host: Error indexing method 'Funct
ion1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twilio.Re
st.Api.V2010.Account.CreateMessageOptions&'.
[2018-12-02 18:03:44] Function 'Function1.Run' failed indexing and will be disab
led.
[2018-12-02 18:03:44] No job functions found. Try making your job classes and me
thods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.)
make sure you've called the registration method for the extension(s) in your st
artup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).
[2018-12-02 18:03:44] Host initialized (715ms)
[2018-12-02 18:03:44] Host started (743ms)
[2018-12-02 18:03:44] Job host started
[2018-12-02 18:03:44] The following 1 functions are in error:
[2018-12-02 18:03:44] Run: Microsoft.Azure.WebJobs.Host: Error indexing method '
Function1.Run'. Microsoft.Azure.WebJobs.Host: Can't bind TwilioSms to type 'Twil
io.Rest.Api.V2010.Account.CreateMessageOptions&'."
这里是依赖项:
我该如何解决?这是依赖关系的问题还是仅仅是代码的问题?
示例来自以下文档:
答案 0 :(得分:5)
您已引用v2示例创建了v1 Function项目。由于Twilio SDK的不同,v1函数使用SMSMessage
,而v2使用CreateMessageOptions
。因此,只需检查v1 example并修改代码即可。
[FunctionName("Function1")]
[return: TwilioSms(AccountSidSetting = "TwilioAccountSid", AuthTokenSetting = "TwilioAuthToken", From = "xxx")]
public static SMSMessage Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer)
{
var message = new SMSMessage()
{
Body = "Hello thanks for your order!",
To = "xxx"
};
return message;
}
项目仅需要两个依赖项Microsoft.Azure.WebJobs.Extensions.Twilio
和Microsoft.NET.Sdk.Functions
。