c# - Azure Web 作业 : No functions found in another assembly

标签 c# azure-webjobs azure-webjobssdk

我有一个 WebJob 项目 - 称之为项目 A。我想在另一个程序集中定义一些 WebJob 函数 - 称之为程序集 B。

WebJobs 没有找到我在程序集 B 中设置的任何作业函数。我可以将该方法从程序集 B 移动到项目 A,WebJobs 发现它很好 - 所以看起来该方法是正确的.

这是一个在项目 A 中有效但在程序集 B 中无效的作业方法示例:

public static void ProcessQueueMessage([QueueTrigger("logqueue")] string logMessage, TextWriter logger)
{
    logger.WriteLine(logMessage);
}

程序集 B 中的类是公共(public)的。程序集 B 引用了 WebJobs SDK,项目 A 引用了程序集 B。我已通过确保程序集 B 在 A 的域程序集中来验证这一点。

那么,WebJob宿主为什么找不到程序集B中的方法呢?我需要用属性装饰程序集吗?或者做一个自定义类型定位器?

有没有任何人让这样的东西发挥作用的例子?

最佳答案

您很可能遇到依赖性计时问题。 JobHost 将索引当前 AppDomain 中的程序集,因此如果在 JobHost 执行索引时您还没有将任何依赖项加载到您的主 exe 中,那么您的第二个程序集将不会被索引。

最快的解决方法是在 JobHost 进行索引之前手动将其加载到您的应用程序域或使用第二个程序集中的一些代码。

例子:

static void Main(string[] args) {
//Data _dummy = new Data(); // reference a type in the other assembly

AppDomain.CurrentDomain.Load("Assembly2"); // manually load into the current domain

var config = new JobHostConfiguration();

var host = new JobHost(config);
host.RunAndBlock(); }

关于c# - Azure Web 作业 : No functions found in another assembly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276838/

相关文章:

azure - Slowcheetah 为 Azure Webjobs 进行转型

c# - WPF 淡入/淡出只运行一次

C# Winforms DatagridView - 为不同的行设置不同的按钮颜色

c# - 找不到互操作类型“Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService”

node.js - 如何从 Azure WebJobs 调用 EasyAPI?

azure - 从 Azure 函数调用中枚举所有函数描述符

c# - 为 "staging"环境发布 Azure WebJob 时出错

Azure WebJobs SDK 访问队列属性

c# - 将 Big ZipArchive-MemoryStream 上传到 Azure

azure - 在 WebJob SDK 日志清理过程中,我需要具体清除哪些 Blob 容器?