1

I read the suggestions on How to load assemblies in PowerShell?, but I didn't really understand it and I don't know how to apply it to my situation.

I'm trying to load this assembly http://msdn.microsoft.com/en-us/library/system.runtime.serialization.formatters.binary.binaryformatter.aspx so that I can serialize an object, and being very new to powershell I feel like I'm in over my head.

Can anyone guide me to how I go about loading this assembly into a script? I'm getting the error:

make sure that the assembly containing this type is loaded

And when I use Add-Type -Namespace System.Runtime.Serialization.Formatters.Binary it prompts me for information for which I don't know how to provide.

Community
  • 1
  • 1
nullByteMe
  • 6,141
  • 13
  • 62
  • 99

1 Answers1

2

The BinaryFormatter is present in mscorlib.dll and is already loaded. To create a new object, you can do the following:

$formatter = new-object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Just a side note: Namespace parameter has different purpose than the one you've guessed. Read `Get-Help Add-Type -Parameter Namespace` to find out more. – BartekB Sep 12 '13 at 12:26