You are viewing limited content. For full access, please sign in.

Question

Question

Remote Agent Script can't load dependencies

asked on March 15, 2022

I'm trying to install a script along with other dll dependencies into directory `C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScript`. In here I have a script MyScript.dll which has a dependency on MyDependency.dll which is in the same directory.

 

I have added this directory to the plugin_settings.json AllowList like:

 

{
    "RemoteScriptSourcePlugin": {
        "AllowList": [ "C:\\Program Files\\Laserfiche\\ProcessAutomationWorkerAgent\\LFPALocalAgent\\MyScript\\", ".", "C:\\Program Files\\dotnet\\packs\\Microsoft.NETCore.App.Ref\\6.0.1\\ref\\net6.0\\" ],
        "Disabled": false,
        "Timeout": 600000 
    }
}

 

Whenever I attempt to run a script rule with this script it seems to find my script but can't link to my dependency. I get the error:

 

```

Message: Exception has been thrown by the target of an invocation.
        Could not load file or assembly 'MyDependency, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
```

 

I have built an exe to invoke MyScript in the same folder and this runs as expected so I see no reason why when invoked through the remote agent the dependency can't be loaded. 

 

When I move the dependency to the root remote agent folder it is found successfully, loaded and can run without issue by the remote agent. But this isn't idea because I would like to isolate all of my dependencies.

 

Are there any additional setting available in plugin_settings.json or am I missing something?

0 0

Replies

replied on March 15, 2022

Remote Agent is a .Net 4.8 app, it will not load .Net 6 assemblies.

0 0
replied on March 16, 2022

My script and dependencies all target .Net 4. I'm not sure where that reference to .Net 6 came from in the AllowList (thought that was a default value).

 

Again, it does run when I move the dependency to C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyDependency.dll.

 

I think the problem is that it can't load dependencies of the script from locations on the AllowList, only the script itself. I wonder whether maybe the script is loaded by the remote agent reflectively using something like Assembly.LoadFile() which would only load the file but not the other dll dependenciees in the same directory?

0 0
replied on March 16, 2022 Show version history

 You can use fusionlog to see how .Net resolves references and what assemblies it tried to load. Be sure to turn off logging when you're done so it does not just fill your disk.

1 0
replied on March 24, 2022

Thanks I've debugged a little with fusionlog and have noticed something strange.

 

To reiterate, what I want to be able to do is load both "C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScript\MyScript.dll" and "C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScript\MyDependency.dll".

 

I have noticed with fusionlog that it can't load my dependency because it is trying to load only in default context (which is like I suspected):

 

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\Laserfiche.ProcessAutomation.LocalAgent.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency/MyDependency.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency/MyDependency.EXE.
LOG: All probing URLs attempted and failed.

 

It never looks in the directory "C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScript\".

 

The strange thing I can load when I change the name of the subdirectory. e.g. attempt to load both "C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScriptNewName\MyScript.dll" and "C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScriptNewName\MyDependency.dll".

 

Now in fusionlog the dependency loads fine and I can see that instead of using the default load context it finds it with the loadfrom context.

 

LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\Laserfiche.ProcessAutomation.LocalAgent.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency/MyDependency.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyDependency/MyDependency.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Laserfiche/ProcessAutomationWorkerAgent/LFPALocalAgent/MyScriptNewName/MyDependency.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyScriptNewName\MyDependency.dll
LOG: Entering download cache setup phase.
LOG: Assembly Name is: MyDependency, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
WRN: A duplicate assembly was found while copying the assembly item to the cache.
LOG: Binding succeeds. Returns assembly from C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\_cache\Laserfiche.ProcessAutomation.LocalAgent.exe\assembly\dl3\0c2d1d31\dfe56e95_b137d801\MyDependency.dll.
LOG: Assembly is loaded in LoadFrom load context.
0 0
replied on November 21, 2023 Show version history

For this "The strange thing I can load when I change the name of the subdirectory. e.g. attempt to load both" where are you changing the name of the subdirectory and how are you trying to "attempt to load both"? If it works I will try it but I don't understand what changes you are making where.

I'm just trying to use Newtonsoft.Json and I continue to get:

A FileNotFound exception has occurred. --> Could not load file or assembly 'MyScript.dll' or one of its dependencies. The system cannot find the file specified. --> The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
 

replied on March 16, 2022

My script and dependencies all target .Net 4. I'm not sure where that reference to .Net 6 came from in the AllowList (thought that was a default value).

 

Again, it does run when I move the dependency to C:\Program Files\Laserfiche\ProcessAutomationWorkerAgent\LFPALocalAgent\MyDependency.dll.

 

I think the problem is that it can't load dependencies of the script from locations on the AllowList, only the script itself. I wonder whether maybe the script is loaded by the remote agent reflectively using something like Assembly.LoadFile() which would only load the file but not the other dll dependenciees in the same directory?

You are not allowed to follow up in this post.

Sign in to reply to this post.