Search code examples
c#dlldllimportdllregistration

How can I tell my C# project where to look for DLLs?


I'm currently trying to use custom functions with JUST.Net.

I've created this function in a project called Foo.JUST.CustomFunctions:

using Newtonsoft.Json.Linq;

namespace CustomFunctions;

public class Normalizer
{
    public static object TryUnquote(object value) =>
        value is string quotedValue
            ? JToken.Parse(quotedValue)
            : value;
}

I am trying to register it with:

// FIXME: Use Dependency Injection!
JUSTContext context = new();

context.RegisterCustomFunction("Enpal.JUST.CustomFunctions", "CustomFunctions.Normalizer", "TryUnquote", "tryunquote");

But the system throws this exception:

System.IO.FileNotFoundException: 'Could not load file or assembly 'C:\projects\SalesforceEventListenerService\Salesforce.EventListener\Foo.JUST.CustomFunctions.dll'. The system cannot find the file specified.'

Which makes perfect sense because Visual Studio is not putting it there when it builds the project but rather it can be found in "C:\projects\SalesforceEventListenerService\Salesforce.EventListener\bin\Debug\net6.0-windows8.0"

How can I make sure the system looks in the right place?

And what, if anything, more will I need to do to make sure this also works when it hits the Azure DevOps CI/CD pipeline?


Solution

  • I was able to get this working like so:

    _ = Assembly.GetAssembly(typeof(Normalizer));
    
    JUSTContext context = new();
    context.RegisterCustomFunction("Enpal.JUST.CustomFunctions", "CustomFunctions.Normalizer", "TryUnquote", "tryunquote");