Open TiJanna720 opened 3 years ago
This error means that you are trying to load from a network share. The module expand and save the native DLL into the temp folder. If the profile is set to the network share, the temp folder is also in the share. Let’s suppose that you have the module in c:\test, then run this before importing the module.
$env:TMP="C:\test"
$env:TEMP=$env:TMP
Import-Module c:\test\OneDriveLib.dll
Don’t worry about changing the variable, it only changes for this session. When you open again or use a different application temp will point to the original place.
Hello,
Thank you for the reply. Unfortunately, that did not work I am still getting the same error. The Local AppData and Temp folder was not on the network shares, they were still at the default location in the users profile on c:. Could it be related to a redirected AppData Roaming folder?
Thanks, Tom
I get this same error. The dll is in my C:\Users\Username\Downloads folder and not on any network share. Running it in Powershell ISE in user context. I tried redefining temp variables and that did not change the error.
This had some recommendations for updating the code: https://stackoverflow.com/questions/39936712/cannot-load-dll-assembly-in-windows-10-exception-from-hresult-0x80131515
I tried :
But unfortunately, got the exact same error.
Looking at the inner exception, it does think it's running from a network location for some reason:
$Error[0].Exception.InnerException.InnerException An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
Eh... Ok, so I feel stupid, but escaping the slashes seem to fix it
Import-Module "C:\\Users\\username\\Downloads\\OneDriveLib.dll"
Get-ODStatus
Nevermind, the escaping is not what fixed it. It was the environment it was run in.
If you already have a Powershell window open, download the file, then unblock it, the existing powershell window will not recognize the unblock. So you need to open a fresh powershell window or the file will not be unblocked.
Hello,
I am trying to import the module and getting the error: Import-Module : Could not load file or assembly 'file:///C:\test\OneDriveLib.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
the import line is :
Import-Module c:\test\OneDriveLib.dll
I have already unblocked the file and I have set the ExecutionPolicy to unrestricted and bypass for testing, I am also not running powershell elevated as per all your other suggestions... Do you have any other suggestions on why it not working? I have it working on my personal pc, which is not a part of the domain, but when I try it on a pc on the domain it fails with this error. I have also installed powershell 7 on the test pc and I am able to load the module in that, but not the built in powershell 5.1. I have tried on 2 win 10 boxes, one was 1809 and the other was 1909 and both fail. I have also put the pc and blocked all GPO just in case but it still will not import the dll.. are there any other dependencies that are required to get it to work?
Thanks!