locked
Problems when loading Assemblies in PowerShell RRS feed

  • Question

  • Hi there,

    I#m currently building a powershell transfer script that uses the WinSCP .NET assembly in order to upload files. I have defined a class in which I'm initializing things like the WinSCP.SessionOptions etc. These types are defined in the WinSCPnet.dll. At the beginning of my script I'm importing the assembly with

    Add-Type -Path <Path-to-assembly.dll>

    Later in my class definition I have a variable like this that is not yet initialized

    [WinSCP.SessionOptions]$Script:SessionOption

    When I try to run the script I always get "Type not found" error referencing to the line where I'm declaring the uninitialized variable. Thiis problem is not limited to the WinSCP assemblies. I'm also getting it when I call a static method no matter if it's a system or a custom assembly. It's also not possible to debug the problem because no breakpoint is reached.

    What can I do to solve that?

    Thanks in advance

    Update-Trobleshoooter

    Friday, February 15, 2019 11:49 AM

All replies

  • You might make your life a little easier  ....  https://www.powershellgallery.com/packages/WinSCP/5.13.7.0 ... no need to re-invent the wheel


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Friday, February 15, 2019 11:55 AM
  • I already know that module and I'm already using it. In my case I need some further information that I handle in a class. In this class I have a method that performs some logging tasks and calls the upload method from the WinSCP module. My problem is that I can't run my script because PowerShell says that it can't find the types before even getting to importing the module.
    Friday, February 15, 2019 12:07 PM
  • You will need to post WinSCP issues here: https://winscp.net/forum/index.php

    This is not a WinSCP forum.


    \_(ツ)_/

    Friday, February 15, 2019 12:17 PM
  • It's not a WinSCP issue. The issue is that PowerShell doesn't recognize the types that are specified in the WinSCPnet.dll. As I already mentioned this is not limited to WinSCP assemblies but I also have it with system assemblies. PowerShell tells me that the type is not found although I added it in the script before using it.
    Friday, February 15, 2019 12:24 PM
  • It's not a WinSCP issue. The issue is that PowerShell doesn't recognize the types that are specified in the WinSCPnet.dll. As I already mentioned this is not limited to WinSCP assemblies but I also have it with system assemblies. PowerShell tells me that the type is not found although I added it in the script before using it.

    That is exactly a WinSCP issue.  You have likely not installed it correctly.  Without your code and the SCP module you are using how do you expect us to know what is happening on your system.  Post in the WinSCP forum and they will help you. 

    The only other guess we can make is that you have a corrupted Net Framework and you need to repair it.

    Also you need to be sure the assembly is compatible with your version of PowerShell.  That is up to WinSCP to decide.


    \_(ツ)_/

    Friday, February 15, 2019 12:29 PM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Thursday, February 28, 2019 9:54 AM