C# 依赖项注入无法启动函数

C# 依赖项注入无法启动函数,c#,azure,dependency-injection,azure-functions,C#,Azure,Dependency Injection,Azure Functions,Azure功能在本地运行良好,当通过部署中心(或发布)部署到Azure时,该功能无法启动,Azure仪表板将显示 Error: The function runtime is unable to start. System.Linq: Value cannot be null. Parameter name: source. Session Id: 353349c4b2c14b2399acd9fa26e79c0b Timestamp: 2019-07-

Azure功能在本地运行良好,当通过部署中心(或发布)部署到Azure时,该功能无法启动,Azure仪表板将显示

    Error:

    The function runtime is unable to start. System.Linq: Value cannot be null.
    Parameter name: source.
    Session Id: 353349c4b2c14b2399acd9fa26e79c0b

    Timestamp: 2019-07-01T20:29:51.503Z
我正在开发一个定时器触发的函数,定期处理数据库中的数据(使用EntityFramework)。该函数将消息发布到StorageQueue。我在本地进行了测试,所有功能都正常运行,访问数据库,处理数据并向StorageQueue发送消息,没有问题

当我部署到Azure时,我会收到上面仪表板中显示的错误消息

我能够将调试器附加到VS2019中的函数,并发现命名空间
Microsoft.Azure.WebJobs.Script.DependencyInjection
,文件
ScriptStartupTypeLocator.cs
中引发了异常

实际功能是

public Type[] GetStartupTypes()
        {
            IEnumerable<Type> startupTypes = GetExtensionsStartupTypesAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            return startupTypes
                .Distinct(new TypeNameEqualityComparer())
                .ToArray();
        }
functions.json

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.29",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "timerTrigger",
      "schedule": "0 */1 * * * *",
      "useMonitor": true,
      "runOnStartup": false,
      "name": "myTimer"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/PlexusDataFeeds.dll",
  "entryPoint": "PlexusDataFeeds.DataFeedSelector.DataFeedSelector.Run"
}
host.json

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.0.6]"
  }
}
extensions.json(来自Azure)

编辑

实际异常为
System.ArgumentNullException:“值不能为null。”
上的
startupTypes

编辑2 我删除了
Willezone.Azure.WebJobs.Extensions.DependencyInjection
NuGet软件包,改为使用
Microsoft.Extensions.DependencyInjection


还是一样的错误。

最后,我没有在我需要的函数中使用依赖项注入和初始化对象。

似乎是部署问题,你能检查一下当你释放函数时,所有需要的二进制文件都在“函数可执行文件”旁边的版本中。

为什么不使用此nuget
Microsoft.Azure.Functions.Extensions.DependencyInjection
@HariHaran,我重新编写了
Configure()
函数,并删除了
Willezone.Azure.WebJobs.Extensions.DependencyInjection
。我无法直接找到Microsoft.Azure.Functions.Extensions.DependencyInjection。我只能找到
Microsoft.Functions.Extensions.DependencyInjection
。是一样的吗?在所有这些更改之后,我仍然看到相同的错误。而且,我没有看到在服务启动中初始化接口的代码。
{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.0.6]"
  }
}
{
  "extensions":[
    { "name": "AzureStorage", "typeName":"Microsoft.Azure.WebJobs.Extensions.Storage.AzureStorageWebJobsStartup, Microsoft.Azure.WebJobs.Extensions.Storage, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"},
    { "name": "ServiceBus", "typeName":"Microsoft.Azure.WebJobs.ServiceBus.ServiceBusWebJobsStartup, Microsoft.Azure.WebJobs.ServiceBus, Version=3.0.6.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"},
    { "name": "Startup", "typeName":"PlexusDataFeeds.Startup, PlexusDataFeeds, Version=0.0.0.1, Culture=neutral, PublicKeyToken=null"}
  ]
}