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.
Locked
User avatar
Genx13
Posts: 12
Joined: Fri May 25, 2018 7:46 am

Project .exe Module .dll Could not load file assembly

Post by Genx13 » Mon Oct 01, 2018 10:01 am

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

Code: Select all

Import-module NTFSSecurity
$HomeDirectory = SomeDirectory
$SAM = SomeUserName
Get-Item $HomeDirectory | Add-NTFSAccess -Account $SAM -AccessRights FullControl

User avatar
jvierra
Posts: 13280
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 01, 2018 10:16 am

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
Joined: Fri May 25, 2018 7:46 am

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

Post by Genx13 » Mon Oct 01, 2018 10:48 am

I ran the

Code: Select all

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

User avatar
jvierra
Posts: 13280
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 01, 2018 11:01 am

Works fine for me. Are you trying to run this from an packaged file (EXE)?

User avatar
Genx13
Posts: 12
Joined: Fri May 25, 2018 7:46 am

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

Post by Genx13 » Mon Oct 01, 2018 11:09 am

Yes
Im using Powershell Studio to build the .exe, It does work if I export it as a .ps1 file.

User avatar
jvierra
Posts: 13280
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Mon Oct 01, 2018 11:18 am

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
Joined: Fri May 25, 2018 7:46 am

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

Post by Genx13 » Tue Oct 02, 2018 9:28 am

So here is an update I did get it to work after some more trial and error, first the

Code: Select all

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

Code: Select all

Import-Module .\AlphaFS.2.2.0.0\Lib\Net40\AlphaFS.dll
Import-Module NTFSSecurity
And everything ran correctly. Thanks to everyone for their help.

Locked