sending-receiving User-defined Objects to MSMQ using send-MSMQMessage

Topics: User Forum
Mar 5, 2010 at 4:27 AM

Hi,

I am trying to send User-Defined Objects to a private Queue using PSCX send-MSMQMessage.

The error that I am getting here is :

There was an error generating the XML document.

At :line:62 char:16

+ Send-MSMQMessage <<<< -InputObject $person -queueName "MyQueue" -MachineName "MyMachine" -private

Is there a way to send objects to a queue using PSCX send-MSMQMessage?

Looking forward to your help.

The code snippet that I am using to send message is below.

Add-PSSnapin PSCX
function New-Type {
   param([string]$TypeDefinition,[string[]]$ReferencedAssemblies)
   
   ## Obtains an ICodeCompiler from a CodeDomProvider class.
   $provider = New-Object Microsoft.CSharp.CSharpCodeProvider
   ## Get the location for System.Management.Automation DLL
   $dllName = [PsObject].Assembly.Location
   ## Configure the compiler parameters
   $compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters

   $assemblies = @("System.dll", $dllName)
   $compilerParameters.ReferencedAssemblies.AddRange($assemblies)
   if($ReferencedAssemblies) { 
      $compilerParameters.ReferencedAssemblies.AddRange($ReferencedAssemblies) 
   }

   $compilerParameters.IncludeDebugInformation = $true
   $compilerParameters.GenerateInMemory = $true

   $compilerResults = $provider.CompileAssemblyFromSource($compilerParameters, $TypeDefinition)
   if($compilerResults.Errors.Count -gt 0) {
     $compilerResults.Errors | % { Write-Error ("{0}:`t{1}" -f $_.Line,$_.ErrorText) }
   }
}

New-type @"
using System;
	public class Person {
		public string Name;
		public int Age;
		public Person (string name, int age){
			Name =name; Age=age;
	}
}
"@

$person = New-Object Person "Amol",29
$person.Name

Send-MSMQMessage -InputObject $person -queueName "MyQueue" -MachineName "MyMachine" -private
Remove-PSSnapin PSCX

Developer
Mar 5, 2010 at 5:09 AM
I think you forgot to mark Person [Serializable]
 
-Oisin

On Thu, Mar 4, 2010 at 11:27 PM, amolz80 <notifications@codeplex.com> wrote:

From: amolz80

Hi,

I am trying to send User-Defined Objects to a private Queue using PSCX send-MSMQMessage.

The error that I am getting here is :

There was an error generating the XML document.

At :line:62 char:16

+ Send-MSMQMessage <<<< -InputObject $person -queueName "MyQueue" -MachineName "MyMachine" -private

Is there a way to send objects to a queue using PSCX send-MSMQMessage?

Looking forward to your help.

The code snippet that I am using to send message is below.

Add-PSSnapin PSCX
function New-Type {
   param([string]$TypeDefinition,[string[]]$ReferencedAssemblies)
   
   ## Obtains an ICodeCompiler from a CodeDomProvider class.
   $provider = New-Object Microsoft.CSharp.CSharpCodeProvider
   ## Get the location for System.Management.Automation DLL
   $dllName = [PsObject].Assembly.Location
   ## Configure the compiler parameters
   $compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters

   $assemblies = @("System.dll", $dllName)
   $compilerParameters.ReferencedAssemblies.AddRange($assemblies)
   if($ReferencedAssemblies) { 
      $compilerParameters.ReferencedAssemblies.AddRange($ReferencedAssemblies) 
   }

   $compilerParameters.IncludeDebugInformation = $true
   $compilerParameters.GenerateInMemory = $true

   $compilerResults = $provider.CompileAssemblyFromSource($compilerParameters, $TypeDefinition)
   if($compilerResults.Errors.Count -gt 0) {
     $compilerResults.Errors | % { Write-Error ("{0}:`t{1}" -f $_.Line,$_.ErrorText) }
   }
}

New-type @"
using System;
	public class Person {
		public string Name;
		public int Age;
		public Person (string name, int age){
			Name =name; Age=age;
	}
}
"@

$person = New-Object Person "Amol",29
$person.Name

Send-MSMQMessage -InputObject $person -queueName "MyQueue" -MachineName "MyMachine" -private
Remove-PSSnapin PSCX

Read the full discussion online.

To add a post to this discussion, reply to this email (Pscx@discussions.codeplex.com)

To start a new discussion for this project, email Pscx@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com




--

---
404 signature missing
Mar 5, 2010 at 5:28 AM

Hi Oisin,

I marked the class as Serializable. But that didnt help. I still get the same error. Is there as different way to create custom objects and pass them to the queue?

Regards,

Amol