working with self made dlls in assembly

Welcome Forums General PowerShell Q&A working with self made dlls in assembly

This topic contains 5 replies, has 2 voices, and was last updated by

 
Participant
5 years, 1 month ago.

  • Author
    Posts
  • #11468

    Participant
    Points: 0
    Rank: Member

    i created dll called myTools.dll, put it in the GAC (assembly), and i see it there.
    i want to load this dll and access it's static methods.
    i tried to do
    Add-Type -AssemblyName myTools;
    and get error that

    Add-Type : Cannot add type. The assembly 'myTools' could not be found.

    any idea?what do i miss?

  • #11473

    Member
    Points: 0
    Rank: Member

    How did you add your assembly to the GAC? If Add-Type is failing, odds are that wasn't done properly. See this link.

  • #11478

    Participant
    Points: 0
    Rank: Member

    drag and drop to the assembly
    i accees it with no problem from web pages.

  • #11479

    Participant
    Points: 0
    Rank: Member

    when i do

    [Reflection.Assembly]::LoadFile("C:\Windows\assembly\GAC_MSIL\meTools\3.5.0.0__88692d87fab243d7\myTools.dll").GetTypes()

    this works.
    can i some how access like this the static methods?

  • #11480

    Member
    Points: 0
    Rank: Member

    I'm pretty sure you're not adding the assembly to the GAC properly if you just dragged and dropped a DLL into that location, but I'm not certain. Anyhow, if that call to Assembly.LoadFile works, then you should be able to load it this way with the Path parameter instead of AssemblyName:

    Add-Type -Path 'C:\Windows\assembly\GAC_MSIL\meTools\3.5.0.0__88692d87fab243d7\myTools.dll'
    
  • #11534

    Participant
    Points: 0
    Rank: Member

    this way worked
    Get-ChildItem -recurse "C:\Windows\assembly\GAC_MSIL\myTools\3.5.0.0__88692d87fab243d7\"|Where-Object {($_.Extension -EQ ".dll") -or ($_.Extension -eq ".exe")} | ForEach-Object { $AssemblyName=$_.FullName; Try {[Reflection.Assembly]::LoadFile($AssemblyName)} Catch{ "***ERROR*** Not .NET assembly: " + $AssemblyName}}

The topic ‘working with self made dlls in assembly’ is closed to new replies.