2
votes

I have a WebJob project - call it project A. I'd like to define some WebJob functions in another assembly - call it assembly B.

WebJobs doesn't find any of the job functions that I've set up in assembly B. I can move the method from assembly B into project A, and WebJobs finds it just fine - so it seems that the method is correct.

Here's an example of a job method that works in project A but not in assembly B:

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

The class in assembly B is public. Assembly B has a reference to the WebJobs SDK, and project A has a reference to assembly B. I've verified this by ensuring that assembly B is in the domain assemblies for A.

So, why can't the WebJob host find the method in assembly B? Do I need to decorate the assembly with an attribute? Or do a custom type locator?

Any examples of anyone getting something like this to work?

1
Is it working for some your functions ? all QueueTrigger ?Thomas
@Thomas - not exactly sure what you mean. The function I posted above does work in the WebJob project (project A). The JobHost indicates that it has found the function in the log. However, when I take the same function and put it in assembly B, the JobHost doesn't find it. This is happening for every trigger function in A, and none of the trigger functions in B. Does that answer your question?Matt Cline

1 Answers

2
votes

Most likely you have a dependency timing issue. The JobHost is going to be indexing the assemblies in the current AppDomain, so if you haven't had any dependencies loaded into your main exe by the time the JobHost does its indexing, then your second assembly won't get indexed.

The quickest fix is to just manually load it into your app domain or use some code that is in that second assembly - before the JobHost does its indexing.

Example:

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