Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, September 19, 2014 8:51 PM
ObjectSender project is to send a class object to a message queue.
ObjectReceiver project is to receive that class object from the message queue.
Both ObjectSender and ObjectReceiver projects are "console application".
I am able to send an object message (class myClass) to a message queue, but when I tried to receive the message from the message queue, I am getting the below error "System.Runtime.Serialization.SerializationException: Unable to find assembly"
in this line of code:
MyClass obj = (MyClass) objMesg.getObject()
"System.Runtime.Serialization.SerializationException: Unable to find assembly 'ObjectSender, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.\r\n
at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()\r\n
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)\r\n
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)\r\n
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped record)\r\n
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadObjectWithMapTyped(BinaryHeaderEnum binaryHeaderEnum)\r\n
at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()\r\n
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)\r\n
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)\r\n
at fiorano.csharp.util.Converter.bytesToObject(Byte[] data)\r\n
at fiorano.csharp.util.FioranoBinaryReader.readObject()\r\n
at fiorano.csharp.services.msg.FioranoObjectMessage._setDataBytes()"
I get this error either by including myClass.cs in both ObjectSender and ObjectReceiver projects, and also when I created a DLL for myClass.cs, and including that DLL in both ObjectSender and ObjectReceiver projects.
How can I fix this error ?
Thank you.
All replies (5)
Monday, September 22, 2014 4:23 PM âś…Answered
Never mind.
The problem is solved. I created a new DLL, and included that DLL in both the ObjectSender and ObjectReceiver projects, and I don't get an error anymore. Not sure why I got the error earlier.
Thanks.
Monday, September 22, 2014 3:24 AM
Hi aujong,
Are you developing an application with MSMQ or some other 3rd-party message queue libraries? How doese the message queue work?
We can't identify the cause of this problem if you don't post some more code and description. According to the error message, I guess the ObjectReceiver is trying to get the assembly infomation from the GAC, but the message queue didn't register the assembly properly in the GAC. So the problem seems to be located in the message queue itself.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Monday, September 22, 2014 1:39 PM
Thank you for your reply.
This is with 3rd-party message queue library.
You are correct that the problem is because of the GAC.
Once I put myClass.DLL in GAC, I don't get the error anymore. This is what I did:
1. I created a class library myClass
2. In myClass project property, in the Signing tab, I clicked "Sign the assembly", and click "New" in the "Choose a strong name key file", entered the key file name and its password.
3. Build myClass.DLL
4. Go to command prompt, and type in this:
gacutil -i "C:\myFolder\myClass.DLL"
After this, I don't get the error message anymore in this line of code:
MyClass obj = (MyClass) objMesg.getObject()
So, just by putting either myClass.cs in both ObjectSender and ObjectReceiver projects, or by putting myClass.DLL in the same folder with the ObjectSender and ObjectReceiver EXEs, that's not the same with having it in GAC ?
Monday, September 22, 2014 1:52 PM
This is the code from myClass.cs
using System;
using System.Runtime.Serialization;
[Serializable]
public class MyClass
{
private string data;
public string getString()
{
return data;
}
public void setString(string msg)
{
data = msg;
}
}
This is the code from ObjectSender project
System.Collections.Hashtable env = new System.Collections.Hashtable();
env.Add(FioranoContext.PROVIDER_URL, url);
FioranoNamingContext ic = new FioranoNamingContext(env);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ic.lookup(qcf);
Queue queue = (Queue) ic.lookup(queueName);
QueueConnection qc = queueConnectionFactory.createQueueConnection();
qc.setExceptionListener(new ObjectSender());
qc.start();
QueueSession qs = qc.createQueueSession(false, SessionConstants.AUTO_ACKNOWLEDGE);
QueueSender sender = qs.createSender(queue);
ObjectMessage message = qs.createObjectMessage();
MyClass obj = new MyClass();
for (int i = 1; i <= 2; i++)
{
obj.setString("Object Message " + i);
message.setObject(obj);
sender.send(message, DeliveryMode.PERSISTENT, 4, 0);
}
This is the code from ObjectReceiver project
System.Collections.Hashtable env = new System.Collections.Hashtable();
env.Add(FioranoContext.PROVIDER_URL, url);
FioranoNamingContext ic = new FioranoNamingContext(env);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ic.lookup(qcf);
Queue queue = (Queue) ic.lookup(queueName);
QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
queueConnection.setClientID("Object_Receiver");
queueConnection.setExceptionListener(new ObjectReceiver());
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(false, SessionConstants.AUTO_ACKNOWLEDGE);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
for (int i = 1; i <= 10; i++)
{
ObjectMessage objMesg = (ObjectMessage) queueReceiver.receive();
MyClass obj = (MyClass) objMesg.getObject();
-->>> ERROR HERE
Monday, September 22, 2014 4:36 PM
Never mind.
The problem is solved. I created a new DLL, and included that DLL in both the ObjectSender and ObjectReceiver projects, and I don't get an error anymore. Not sure why I got the error earlier.
Thanks.
You got the original error because, despite the name similarities, you had mismatched type definitions. You were sending one type definition, while trying to receive with a different type definition. Putting the type definition into a DLL that was used by both programs corrected the mismatched type definitions.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."