Author Posts

November 14, 2013 at 7:25 am

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?

November 14, 2013 at 8:01 am

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

November 14, 2013 at 8:16 am

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

November 14, 2013 at 8:17 am

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?

November 14, 2013 at 8:53 am

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'

November 17, 2013 at 12:34 am

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