![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | BinaryFormatter problem I faced some problem with BinaryFormatter. Deserialize method doesn't work when I run it from PowerShell Cmdlet, while it works normally in test application. I have found only one solution - place dll in GAC, is it correct way? Here is example. It fails on deserialize method telling that it cannot load assembly. [Serializable] public class Test { private int num; public int Num { get { return num; } set { num = value; } } } ProcessRecord method of cmdlet. protected override void ProcessRecord() { BinaryFormatter sr = new BinaryFormatter(); MemoryStream st = new MemoryStream(); Test t = new Test(); t.Num = 100; sr.Serialize(st, t); st.Position = 0; Test t2 = (Test)sr.Deserialize(st); st.Close(); this.WriteObject(t2); } |
My System Specs![]() |
| | #2 (permalink) |
| | RE: BinaryFormatter problem Presumably the dll you want to use contains the .NET assembly. You could put it in the GAC then use $null= [System.Reflection.Assembly]::LoadWithPartialName(partial_name_of_assembly) or load it direct $null = [System.Reflection.Assembly]::LoadFrom(full_path_to_assembly) -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Andrew" wrote: > I faced some problem with BinaryFormatter. > Deserialize method doesn't work when I run it from PowerShell Cmdlet, while > it works normally in test application. > I have found only one solution - place dll in GAC, is it correct way? > > Here is example. It fails on deserialize method telling that it cannot load > assembly. > > [Serializable] > public class Test > { > private int num; > public int Num > { > get { return num; } > set { num = value; } > } > } > > ProcessRecord method of cmdlet. > protected override void ProcessRecord() > { > BinaryFormatter sr = new BinaryFormatter(); > MemoryStream st = new MemoryStream(); > Test t = new Test(); > t.Num = 100; > sr.Serialize(st, t); > st.Position = 0; > Test t2 = (Test)sr.Deserialize(st); > st.Close(); > this.WriteObject(t2); > } |
My System Specs![]() |
| | #3 (permalink) |
| | RE: BinaryFormatter problem Sorry - misread your post. If you are creating a cmdlet - you need to put a reference to the assembly in your project and a using statement in the code -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Andrew" wrote: > I faced some problem with BinaryFormatter. > Deserialize method doesn't work when I run it from PowerShell Cmdlet, while > it works normally in test application. > I have found only one solution - place dll in GAC, is it correct way? > > Here is example. It fails on deserialize method telling that it cannot load > assembly. > > [Serializable] > public class Test > { > private int num; > public int Num > { > get { return num; } > set { num = value; } > } > } > > ProcessRecord method of cmdlet. > protected override void ProcessRecord() > { > BinaryFormatter sr = new BinaryFormatter(); > MemoryStream st = new MemoryStream(); > Test t = new Test(); > t.Num = 100; > sr.Serialize(st, t); > st.Position = 0; > Test t2 = (Test)sr.Deserialize(st); > st.Close(); > this.WriteObject(t2); > } |
My System Specs![]() |
| | #4 (permalink) |
| | RE: BinaryFormatter problem There is only one assembly (Cmdlet) containing class Test (that must be serialized and deserialized) and Cmdlet. Exception is like this: Unable to find assembly xxx'. at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name) at System.Runtime.Serialization.Formatters.Binary.ObjectMap..ctor(String objectName, String[] memberNames, BinaryTypeEnum[] binaryTypeEnumA, Object[] typeInformationA, Int32[] memberAssemIds, ObjectReader objectReader, Int32 objectId, BinaryAssemblyInfo assemblyInfo, SizedArray assemIdToAssemblyTable) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum) at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run() at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) at myCmdLets.test.ProcessRecord() "RichS" wrote: > Sorry - misread your post. > > If you are creating a cmdlet - you need to put a reference to the assembly > in your project and a using statement in the code > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "Andrew" wrote: > > > I faced some problem with BinaryFormatter. > > Deserialize method doesn't work when I run it from PowerShell Cmdlet, while > > it works normally in test application. > > I have found only one solution - place dll in GAC, is it correct way? > > > > Here is example. It fails on deserialize method telling that it cannot load > > assembly. > > > > [Serializable] > > public class Test > > { > > private int num; > > public int Num > > { > > get { return num; } > > set { num = value; } > > } > > } > > > > ProcessRecord method of cmdlet. > > protected override void ProcessRecord() > > { > > BinaryFormatter sr = new BinaryFormatter(); > > MemoryStream st = new MemoryStream(); > > Test t = new Test(); > > t.Num = 100; > > sr.Serialize(st, t); > > st.Position = 0; > > Test t2 = (Test)sr.Deserialize(st); > > st.Close(); > > this.WriteObject(t2); > > } |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| the problem with ndis.sys Blue Screen of Death problem solved? | Vista General | |||
| Re: Windows Mail Attachement Problem and Adobe Player Problem with IE8 | Vista mail | |||
| Generic McAfee Problem Message in Vista Problem Reports | Vista performance & maintenance | |||
| audio problem with my sony vaio laptop and x64 problem | Vista hardware & devices | |||
| Vista Upgrade Problem - Windows Explorer Loop problem | Vista installation & setup | |||