working with self made dlls in assembly

This topic contains 5 replies, has 2 voices, and was last updated by  wantto wantto 3 years, 9 months ago.

  • Author
    Posts
  • #11468

    wantto wantto
    Participant

    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

    Dave Wyatt
    Moderator

    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

    wantto wantto
    Participant

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

  • #11479

    wantto wantto
    Participant

    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

    Dave Wyatt
    Moderator

    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

    wantto wantto
    Participant

    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}}

You must be logged in to reply to this topic.