Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Error in serializing ImaqdxException

Hi All,

 

I am trying to clone an ImaqdxException object using binary serialization and deserialization. I find that the serialization part is going fine but however, the deserialization throws up an error. Please find the sample code below

 

ImaqdxException exception = new ImaqdxException("Some Exception");
BinaryFormatter Formatter = new BinaryFormatter();
using (var ms = new MemoryStream())
{
Formatter.Serialize(ms, exception);
ms.Position = 0;

ImaqdxException replica = (ImaqdxException)Formatter.Deserialize(ms);
}

 

The exception I am getting is as follows

 

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Serialization.SerializationException: Member 'Error' was not found.\r\n at System.Runtime.Serialization.SerializationInfo.GetElement(String name, Type& foundType)\r\n at System.Runtime.Serialization.SerializationInfo.GetInt32(String name)\r\n at NationalInstruments.Vision.Acquisition.Imaqdx.ImaqdxException..ctor(SerializationInfo info, StreamingContext context)\r\n --- End of inner exception stack trace ---\r\n at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)\r\n at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)\r\n at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)\r\n at System.Runtime.Serialization.ObjectMana
ger.FixupSpecialObject(ObjectHolder holder)\r\n at System.Runtime.Serialization.ObjectManager.DoFixups()\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 TestIMAQdxCameraDriver.TestForm..ctor() in C:\\Development\\Projects\\CODA\\TestIMAQdxCameraComponent\\TestForm.cs:line 52

 

From the exception I believe that there was a mistake in missing out writing the "Error" property when serializing and when deserializing it is expecting to get that property.

 

I am using Measurement Studio 2010.

 

Thanks,

 

Venkat

0 Kudos
Message 1 of 9
(4,307 Views)

Hello Venkat,

 

What happens if you call ms.Error? Also, what happens if you call exception.Error? (From your example code). We could easily isolate the issue to the deserialization or the serialization in this way.

Colden
0 Kudos
Message 2 of 9
(4,286 Views)

Hi Colden,

 

Thank you for your time and reply. I really cannot do a ms.Error because Error is not a property of ms. I can however see a valid Error object as part of the original "exception" that I created. I believe that the Error is not being put as part of the serialization when the VisionException is serialized. And so when it is deserializing, it expects "Error" but cannot find it. There is no way by which we can find whether the Error property is being serialized, unless we dig into the code of VisionException. If you would like, I can do that using a tool like reflector but I am sure you can do that a lot easier since you have access to the source code for VisionException.

 

Thanks,

 

Venkat

0 Kudos
Message 3 of 9
(4,282 Views)

Hello Venkat,

 

I'm not sure why the serialization is not working with the Error property of ImaqdxException. "Error" is the only property of ImaqdxException, so that may be related.

 

That said, have you tried the GetObjectData method for ImaqdxException? From the help it looks like it should return a serialized version of the ImaqdxException.

Colden
0 Kudos
Message 4 of 9
(4,260 Views)

Hi Colden,

 

Thank you for your time and reply. I beileve the binary formatter serializer makes use of the GetObjectData method to serialize the exception.

 

Also, I am afraid, I cannot say whether the result I am getting by the call to GetObjectData contains the Error property because the only way to find out is to invoke the constructor "protected ImaqdxException(SerializationInfo info, StreamingContext context)" and see the members of the newly created exception clsass; However, this constructor is protected and not public. Also, I believe binary formatter serialization does exactly these serialization and deserialization steps and there seems to be some problem mostly with the serialization I believe. I think it needs to be looked into from the source code level and we do not have the source code.

 

We find that the capabaility to deep clone the ImaqdxException using binary formatter to be a very useful functionality. Else we need to wrap all the methods we call to the ImaqdxCamera driver in a try catch and copy the exception text from the caught ImaqdxException to a newly created Exception object and throw the newly created exception object. This involves more work for us.

 

Can you please let me know whether you have a fix for this problem.

 

Thanks,

 

Venkat

0 Kudos
Message 5 of 9
(4,250 Views)

Hello Rham,

 

I'm working on reproducing this issue and communicating with R&D about it. It's may take a while - I'll keep you posted.

Colden
0 Kudos
Message 6 of 9
(4,226 Views)

Thank you Colden for the update. Please let me know if you need any further infrormation and also once the issue gets fixed.

0 Kudos
Message 7 of 9
(4,206 Views)

Hi NI Machine Vision Team,

 

I was wondering if you were able to reproduce this issue and were able to fix it.

 

Thanks,

 

Venkat

0 Kudos
Message 8 of 9
(4,162 Views)

Hello Venkat,

 

We have reproduced the issue, but the time until fix will be a while, because it is something that would be fixed in a future release of the driver.

Colden
0 Kudos
Message 9 of 9
(4,160 Views)