LoginSignup
0
0

More than 1 year has passed since last update.

AzureのTimerTrigger Functionを手動実行した際の「Object reference not set to an instance of an object.」エラー原因と対応

Posted at

事象

Azureで、TImerTriggerのFunctionを手動実行(Azureポータルの「コードとテスト」から実行)をすると下記のエラーが出力されます。

Object reference not set to an instance of an object.

原因

TimerTriggerFunctionは、デフォルトとしてタイマーオブジェクトを必須引数として指定しています。
しかし、このタイマーオブジェクトは、トリガーとなるタイマーから起動された場合のみしかFunctionに受け渡されず、手動実行した場合タイマーオブジェクトはFunctionに受け渡されません。
https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-bindings-timer?tabs=csharp#manually-invoke-a-timer-trigger

上記仕様により、Functionが手動実行された場合、必須引数であるタイマーオブジェクトを参照できずエラーが発生してしまいます。

対策

タイマーオブジェクトを任意引数とする。

修正前

        public async Task RunAsync(
            ~~
            TimerInfo timer,
        {

修正後

        public async Task RunAsync(
            ~~
            TimerInfo timer?,
        {

同じ事象で悩んでいる方の一助になれば幸いです。
他にも対策方法があれば教えていただきたいです!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0