Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializing custom subject types throws XML exception #850

Closed
glopesdev opened this issue Feb 20, 2022 · 1 comment
Closed

Serializing custom subject types throws XML exception #850

glopesdev opened this issue Feb 20, 2022 · 1 comment
Labels
bug Something isn't working
Milestone

Comments

@glopesdev
Copy link
Member

When saving workflows containing custom generic subject builder types derived from SubjectBuilder<T>, the XML serialization throws an error message complaining about duplicate types.

Digging deeper it looks like there might be a fundamental issue with XML serialization of generic types when the serialized types are not part of the default XML namespace (and thus contain qualified namespace prefix strings such as p1:CustomType , etc).

In these cases, the encoding and decoding of generic type names seems not to account for the existence of XML prefixes. For example, during serialization:

var typeName = XmlConvert.DecodeName(text);
if (genericTypes.TryGetValue(typeName, out GenericTypeCode type))

In this case, if the decoded text is a XML qualified name containing a prefix, the generic type map will not recognize the type signature, as XML prefixes are unique only within the specific document scope. The correct behavior would be to send to the lookup the fully expanded type name without the XML prefix. This would suffice as the namespace is already fully expanded in previous steps.

Conversely, during deserialization:

if (value.Length != genericSeparatorIndex)
{
// fast comparison for clipping internal type suffixes only
typeRef.BaseType = type.Namespace + "." + value + type.Name.Substring(genericSeparatorIndex);
}
var typeName = codeProvider.GetTypeOutput(typeRef);
value = XmlConvert.EncodeName(typeName);

The expanding of typeRef.BaseType with the type namespace fails to account for the fact that the base type string value might contain a XML qualified name with a prefix, in which case the string to be encoded might end up having the format MyNamespace.p1:MyType instead of p1:MyNamespace.MyType.

@glopesdev glopesdev added the bug Something isn't working label Feb 20, 2022
@glopesdev glopesdev added this to the 2.7.0 milestone Feb 20, 2022
@glopesdev
Copy link
Member Author

Closed in 6da42c0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant