孤立的 Azure 函数在启动时引发错误。

huangapple go评论81阅读模式
英文:

Isolated Azure Function throwing error on startup

问题

我正在努力将所有我们的C# Azure函数转换为与进程隔离,但遇到了一个我找不到任何信息的错误。我在启动时收到的错误是:

找不到方法: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.RegisterDefaultConverters(Microsoft.Extensions.DependencyInjection.IServiceCollection)'。

我的Program.cs可能再简单不过了:

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
    .Build();
await host.RunAsync();

我的.csproj文件包含了比我需要的扩展更多,但我一直在尝试不同的扩展来看是否会有任何变化:

<PackageReference Include="Microsoft.Azure.AppConfiguration.Functions.Worker" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ApplicationInsights" Version="1.0.0-preview4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.DurableTask" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Warmup" Version="4.0.2" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
英文:

I'm working on converting all of our c# Azure functions to be isolated from in-process but am running into an error that I can't find any information on. The error I am getting on startup is:

> Method not found: 'Microsoft.Extensions.DependencyInjection.IServiceCollection Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions.RegisterDefaultConverters(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.

My Program.cs couldn't be simpler I don't think:

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
    .Build();
await host.RunAsync();

My .csproj has more extensions than I need but been throwing extensions at it to see if anything changes:

&lt;PackageReference Include=&quot;Microsoft.Azure.AppConfiguration.Functions.Worker&quot; Version=&quot;6.0.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.ApplicationInsights&quot; Version=&quot;1.0.0-preview4&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.DurableTask&quot; Version=&quot;1.0.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.CosmosDB&quot; Version=&quot;4.0.1&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Storage&quot; Version=&quot;5.0.1&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues&quot; Version=&quot;5.0.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.6.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Http&quot; Version=&quot;3.0.12&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Timer&quot; Version=&quot;4.1.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Warmup&quot; Version=&quot;4.0.2&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.3.0&quot; /&gt;    
    &lt;PackageReference Include=&quot;Newtonsoft.Json&quot; Version=&quot;13.0.1&quot; /&gt;

答案1

得分: 0

我减少了对包的引用,一切都开始正常工作了。仍然不理解这个错误的含义。

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" />
英文:

I scaled back on my package references and everything started working. Still don't understand what the error means

&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.6.0&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Http&quot; Version=&quot;3.0.12&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues&quot; Version=&quot;5.0.0&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Timer&quot; Version=&quot;4.1.0&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.3.0&quot; /&gt;    

答案2

得分: 0

通常这种异常表示包版本不匹配(特别是当未正确处理破坏性更改时),在这种情况下 `Microsoft.Azure.Functions.Worker` 是罪魁祸首 - 更新它(似乎其中一个依赖项已移除了 `RegisterDefaultConverters` 扩展方法,另外似乎 `Microsoft.Azure.Functions.Worker.Sdk` 也可以/需要更新):

```xml
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.13.0&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.9.0&quot; /&gt;

<details>
<summary>英文:</summary>

Such exceptions usually denote a package version mismatch (especially when breaking changes are not handled correctly), in this particular case  `Microsoft.Azure.Functions.Worker` is the guilty one - update it (it seems that one of the dependencies has removed the `RegisterDefaultConverters` extension method, 
also it seems that `Microsoft.Azure.Functions.Worker.Sdk` can be/needs to be updated also):

```xml
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.13.0&quot; /&gt;
&lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.9.0&quot; /&gt;

huangapple
  • 本文由 发表于 2023年4月4日 03:12:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75922999.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定