Project .exe Module .dll Could not load file assembly

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Project .exe Module .dll Could not load file assembly

Post by Genx13 »

Using Powershell Studio 2017
I have a Script that works normally as a .ps1 that uses the NTFSSecurity Module (https://gallery.technet.microsoft.com/s ... 85#content). If I Build the same files into a .exe the module is imported successfully, but when it comes to running the cmd's associated with the module I get an error.
Add-NTFSAccess : Could not load file or assembly 'AlphaFS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9' or one of its dependencies. The system cannot find the file specified.
I understand this is saying a file can not be found but it runs normally as a script(.ps1). In Powershell Studio The Module is listed and checked in my cache.
Here Is the command
  1. Import-module NTFSSecurity
  2. $HomeDirectory = SomeDirectory
  3. $SAM = SomeUserName
  4. Get-Item $HomeDirectory | Add-NTFSAccess -Account $SAM -AccessRights FullControl
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Project .exe Module .dll Could not load file assembly

Post by jvierra »

Files are not included in an EXE. The module must exist and be in the module path on the target system.

You should start by upgrading to the current version of the module:

Install-Module NTFSSecurity

This will upgrade the module.

Note that you must remove the existing "Gallery" module first by deleting its folder. The old module is not compatible with the PowerShell Gallery version
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Re: Project .exe Module .dll Could not load file assembly

Post by Genx13 »

I ran the
  1. Install-Module NTFSSecurity
Cleared and rebuilt the module cache. Re-Built .exe and Im getting the same error.
Add-NTFSAccess : Could not load file or assembly 'AlphaFS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=4d31a58f7d7ad5c9' or one of its dependencies.
The system cannot find the file specified.
This installed the version 4.2.4 of the module
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Project .exe Module .dll Could not load file assembly

Post by jvierra »

Works fine for me. Are you trying to run this from an packaged file (EXE)?
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Re: Project .exe Module .dll Could not load file assembly

Post by Genx13 »

Yes
Im using Powershell Studio to build the .exe, It does work if I export it as a .ps1 file.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Project .exe Module .dll Could not load file assembly

Post by jvierra »

I can build an EXE with no issues. Since this is a PSS 2017 issue I recommend posting in the REgister Customers forum for PSS and let the Sapien techs look at this. I do not have an installed version of 2017 so I cannot test with that version. Sapien has your version available.

The issue appears to be an issue with the build engine.

Be sure you are building with the correct host.
User avatar
Genx13
Posts: 12
Last visit: Wed Jun 16, 2021 5:29 am

Re: Project .exe Module .dll Could not load file assembly

Post by Genx13 »

So here is an update I did get it to work after some more trial and error, first the
  1. Install-Module NTFSSecurity
Was the right track. I didn't realize the module was 64bit (which could have been because I was running 64bit PS) so it was put in the SysWOW64 Module Directory. After I figured that out I did some more googleing because I was still getting the error. I found the link below which explains Importing the AlphaFS.dll as a module.

https://github.com/alphaleonis/AlphaFS/wiki/PowerShell

The download link from there leads to the page below, where you can download a zip file of multiple AlphaFS versions (Per my Error Message I needed 2.2.0).

https://github.com/alphaleonis/AlphaFS/releases

I unzipped it placed it in the folder with the .exe and added the commands below in that order
  1. Import-Module .\AlphaFS.2.2.0.0\Lib\Net40\AlphaFS.dll
  2. Import-Module NTFSSecurity
And everything ran correctly. Thanks to everyone for their help.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked