OptionalFieldAttribute is causing AugumentNullException on Deseria

J

Jason

I have an application that includes several serializable classes that are all
output using the SOAP formatter. Over the years, I've added several
OptionalFieldAttributes to various members of the classes.

Now, on one particular class I'm trying to add an additional
OptionalFieldAttribute, but when I deserialize the objects I get an
ArgumentNullException with a message of: "Member at position 22 was null."

I can move the new field to a different class and everything works just
fine. This error only happens in the single class where I need this new
attribute.

This is the 8th OptionalField to be added to the class. The actual code is
as follows:
<OptionalFieldAttribute(VersionAdded:=6)> Private _Status As Integer

The top part of the stack trace includes the following:
at
System.Runtime.Serialization.FormatterServices.PopulateObjectMembers(Object
obj, MemberInfo[] members, Object[] data)
at
System.Runtime.Serialization.Formatters.Soap.ReadObjectInfo.PopulateObjectMembers()
at
System.Runtime.Serialization.Formatters.Soap.ObjectReader.ParseObjectEnd(ParseRecord pr)
at
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Parse(ParseRecord
pr)
at
System.Runtime.Serialization.Formatters.Soap.SoapHandler.EndElement(String
prefix, String name, String urn)
at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.Run()
at
System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser)
at
System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream
serializationStream, HeaderHandler handler)
at
System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream
serializationStream)
at ... [my calling function]

I've found a similar post at
http://social.msdn.microsoft.com/Fo.../thread/158d3eae-bc11-4265-994d-ce25f16af0e7/
that did not include a resolution to the problem either.

I'm trying to figure out how to handle this issue so I can serialize this
additional field correctly and handle previously saved data files.

Jason
 
H

Hongye Sun [MSFT]

Hi Jason,

Thanks for using Microsoft Newsgroup Service. My name is Hongye Sun [MSFT]
and it is my pleasure to work with you on this issue.

After my research on this issue, I found that this issue as you described
can be caused by many possibilities and it is hard to tell what caused the
error right now. I need the serializable classes and the xml file that you
are testing on to do further troubleshooting. Can send them to my email
address ([email protected], remove 'online.')?

Here is information for you to do troubleshooting on your side:
One possibility of the issue is caused by duplicate members in xml file. If
there are two fields with same name in xml file, the SOAP formatter is
unable to identify them and report the same exception as you reported.
The duplicate members may look like:
---------------------------------
<m_Image5 xsi:null="1"/>
<m_Image5 xsi:null="1"/>
---------------------------------
m_Image5 is one of the fields in the class.
Can you have a quick check of the xml file and verify that there is no
duplicate in all the members of the error class?

Thanks in advance for your cooperation and I will be waiting for your
reply. Have a nice day.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
H

Hongye Sun [MSFT]

Hello Jason,

Thanks for your reply email. The repro project is very useful for us to do
further troubleshooting.

I have done a deep research on the project and found the cause of the
problem, however, I haven't found the solution yet. I am writing to let you
know the progress of the issue and I will continue to work out a solution
for you. In the meanwhile, I will also consult this issue with product team.

The cause I found is that when a class has a structure field, the
OptionalFieldAttribute will stop working.

I tested it in our lab by setting the fields in the clsSystem class to
NonSerialized one by one and finally found that when mvarColor, which is
type "Color" structure, is set to NonSerialized, everything works fine. (I
also simplified the "ias" file.)

I also proved that by creating another new class with a field whose type is
a user defined structure. It reports me the same error.

Thanks again for your great cooperation. Have a nice day!

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jason

Wow! That's a nasty little bug in the framework. Thank you very much for
identifying it. Now that I know the root cause, I'll probably change the
mvarColor field to a different data type and deprecate the original field.
That way I'll be able to maintain backwards compatibility and be able to move
forward.

I do think this should be corrected in the framework, but I don't want to
subject my users to the need to apply a hot fix in order to use my
application. The configuratoin control just gets too wierd for users at that
point. They already have to upgrade to .net 3.5.

In any case, your answer was very usefull. Again, Thank you for your time.

Jason
 
H

Hongye Sun [MSFT]

You are welcome, Jason. It is my pleasure to work with you.

We are still verifying if this is a bug. I will continue to update the
progress of the issue in this thread. If you are not interested in the
further information, please feel free to let me know. I will close this
issue. Thanks.

Regards,
Hongye Sun ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top