Author Posts

September 22, 2017 at 5:28 pm

I have an issue when trying to load an assembly -Path is coming back as Null. Not sure why but here is my code snippet

Add-Type -Path "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll"
$assemblies=@(
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll"
)
Add-Type $code = @'
using System;
using System.Xml;
using system.Text;

public class testItem
{
     public static string searchMachine()
      {
        return "TEST";
      }
'@
Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $code -Language CSharpVersion3
[testItem]::searchMachine()

September 22, 2017 at 7:36 pm

try this:

$Source = @"
using System;
using System.Xml;
    public class PS
    {
      public static string searchMachine()
      {
        return "TEST";
      }
    }
"@

$referencingassemblies = ("C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll")
Add-Type  -TypeDefinition $Source -ReferencedAssemblies $referencingassemblies -Language CSharp
[PS]::searchMachine()

September 26, 2017 at 3:41 pm

Tried that Rick. Did not work. keeps saying same error Path is null.

September 26, 2017 at 4:03 pm

I did a test-path and it came back true. Not sure why its still erroring

September 26, 2017 at 7:46 pm

GOT IT....noticed I had ADD TYPE for the code part. So instead of ADD-TYPE $code = @" I only need $code = @"