Azure Function无法以错误“程序集z中类型y中的方法x没有实现”开始。

时间:2019-01-11 14:53:48

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

我的Azure Function项目(.NET标准)具有一个名为[HttpGet] public HttpResponseMessage GetFile() { string fileName = @"c:\temp\test.zip"; MemoryStream responseStream = new MemoryStream(); using (FileStream source = File.Open(fileName, FileMode.Open)) source.CopyTo(responseStream); HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StreamContent(responseStream); response.StatusCode = HttpStatusCode.OK; response.Content.Headers.ContentType = new MediaTypeHeaderValue(ContentTypeHelper.Instance.GetFileContentType(fileName)); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentDisposition.FileName = fileName; response.Content.Headers.ContentLength = responseStream.Length; return response; } 的类,该类实现了一个接口Startup.cs,只要该类在项目中,就会引发以下错误。如果我在类中显式实现该接口,则可以通过此错误,但是该函数中的其他类将导致相同的问题。

IFunctionStartup

Startup.cs

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.

IFunctionStartup.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();
    //}
}

这是完整的初始化日志:

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

1 个答案:

答案 0 :(得分:1)

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

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

以下是有关如何对其进行故障排除的一些提示: