【问题标题】:Azure Function fails to start with error "Method x in type y from assembly z does not have an implementation."Azure 函数无法启动,并出现错误“来自程序集 z 的类型 y 中的方法 x 没有实现。”
【发布时间】:2019-02-07 19:45:41
【问题描述】:

我的 Azure Function 项目(.NET 标准)有一个名为 Startup.cs 的类,它实现了一个接口 IFunctionStartup,只要该类在项目中,就会引发以下错误。如果我在类中显式实现接口,我可以通过这个错误,但函数中的其他类会导致同样的问题。

Export: Unable to load one or more of the requested types.
Method 'RegisterDependencies' in type '*****.Startup' 
from assembly '*****.AzureFunction, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
does not have an implementation.

Startup.cs

public class Startup : IFunctionStartup
{
    public void RegisterDependencies(ContainerBuilder builder, IConfiguration configuration)
    {
        builder.RegisterModule(new ApplicationRegistrar(configuration));        
    }

    // This explicit interface implementation gets me pass the error,
    // but doesn't address the root cause, because other classes will
    // start failing with the same error.

    //void IFunctionStartup.RegisterDependencies(ContainerBuilder builder, IConfiguration configuration)
    //{
    //    throw new System.NotImplementedException();
    //}
}

IFunctionStartup.cs

public interface IFunctionStartup
{
    void RegisterDependencies(ContainerBuilder builder, IConfiguration configuration);
}

这是完整的初始化日志:

Azure Functions Core Tools (2.3.199 Commit hash: fdf734b09806be822e7d946fe17928b419d8a289)
Function Runtime Version: 2.0.12246.0
[1/11/2019 2:29:54 PM] Starting Rpc Initialization Service.
[1/11/2019 2:29:54 PM] Initializaing RpcServer
[1/11/2019 2:29:54 PM] Building host: startup suppressed:False, configuration suppressed: False
[1/11/2019 2:29:54 PM] Reading host configuration file '*****\host.json'
[1/11/2019 2:29:54 PM] Host configuration file read:
[1/11/2019 2:29:54 PM] {
[1/11/2019 2:29:54 PM]   "version": "2.0"
[1/11/2019 2:29:54 PM] }
[1/11/2019 2:29:55 PM] Initializing Host.
[1/11/2019 2:29:55 PM] Host initialization: ConsecutiveErrors=0, StartupCount=1
[1/11/2019 2:29:55 PM] Starting JobHost
[1/11/2019 2:29:55 PM] Starting Host (HostId=*****-1139087863, InstanceId=2896b355-b2f7-4ae7-bfc4-403ec9c0d84d, Version=2.0.12246.0, ProcessId=247248, AppDomainId=1, InDebugMode=False, InDiagnosticMode=False, FunctionsExtensionVersion=)
[1/11/2019 2:29:55 PM] Loading functions metadata
[1/11/2019 2:29:55 PM] 1 functions loaded
[1/11/2019 2:29:55 PM] WorkerRuntime: dotnet. Will shutdown other standby channels
[1/11/2019 2:29:56 PM] Generating 0 job function(s)
[1/11/2019 2:29:56 PM] Found the following functions:
[1/11/2019 2:29:56 PM] *****.ExportComplianceDetailsFunction.Run
[1/11/2019 2:29:56 PM]
[1/11/2019 2:29:56 PM] Host initialized (754ms)
[1/11/2019 2:29:56 PM] Host started (767ms)
[1/11/2019 2:29:56 PM] Job host started
[1/11/2019 2:29:56 PM] The following 1 functions are in error:
[1/11/2019 2:29:56 PM] Export: Unable to load one or more of the requested types.
[1/11/2019 2:29:56 PM] Method 'RegisterDependencies' in type '*****.Startup' from assembly '*****.AzureFunction, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.
[1/11/2019 2:29:56 PM]
Hosting environment: Production
Content root path: *****\netstandard2.0
Now listening on: http://0.0.0.0:7071
Application started. Press Ctrl+C to shut down.

【问题讨论】:

  • @RufusL 我同意,但这似乎是我的代码之外的问题。我可以控制 Startup 类和 IFunctionStartup 接口,并且它们的版本是一致的。 Azure Function Host 和我的代码之间似乎存在其他依赖关系,但我找不到解决问题的方法。
  • 我仍然坚持这个,但到目前为止,它似乎与 Azure Functions Host 不支持我的解决方案中的一个(或多个)nuget 包的最新版本有关。顺便说一句,这很难解决。

标签: c# azure azure-functions azure-webjobs


【解决方案1】:

我能够解决问题。根本原因是 Microsoft.EntityFrameworkCore.SqlServer 版本 2.2,目前与 Azure Functions 不兼容。

不幸的是,错误消息与根本原因完全无关,我只能通过反复试验找出不兼容的 nuget。

这里有一些关于如何解决它的提示:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-27
    • 2013-11-20
    相关资源
    最近更新 更多