We are facing some issues where On older API .Net level code was running fine but new .net 4.5 has issues.
Please check below.
Statement below .Net 4.5
_xmlWriter.WriteAttributeString("xmlns:android", "http://schemas.android.com/apk/res/android");
This throw the below exception
Exception in 4.5 when using above statement
ArgumentException: Invalid name character in ‘xmlns:android’. The ‘:’ character, hexadecimal value 0x3A, cannot be included in a name.
Above Code line in .Net 4.5 needs to be converted to
_xmlWriter.WriteAttributeString("xmlns", "android", null, "http://schemas.android.com/apk/res/android");
The same statement below .Net 4.5 is throwing exception saying null can’t be passed.
It would be great if it can be resolved or consistent. If its supposed to work as above, there should be a way to detect which code to use (may be via macros or any api variables)
For further references please check on our forum page .
@JoshPeterson
Thanks,
VB Team
joncham
September 30, 2017, 1:43pm
2
You should be able to check for a NET_4_6 define.
Thanks @joncham . May I know from which Unity version it exists?
Here is the code we have currently due to inconsistencies with 4.6. I hope i it will be fixed soon.
4_6 And Old Compat
protected void WriteAttributeString (XmlWriter _xmlWriter, string _prefix, string _localName, string _nameSpace, string _value)
{
#if UNITY_5_6_OR_NEWER
if (GetAPICompatibilityLevel() == ApiCompatibilityLevel.NET_4_6)
{
if (string.IsNullOrEmpty (_prefix) && string.IsNullOrEmpty (_nameSpace))
_xmlWriter.WriteAttributeString (_localName, _value);
else
_xmlWriter.WriteAttributeString (_prefix, _localName, _nameSpace, _value);
}
else
#endif
{
if (!string.IsNullOrEmpty (_nameSpace))
{
_xmlWriter.WriteAttributeString (_prefix + “:” + _localName, _nameSpace, _value);
}
else if (!string.IsNullOrEmpty (_prefix))
{
_xmlWriter.WriteAttributeString (_prefix + “:” + _localName, _value);
}
else
{
_xmlWriter.WriteAttributeString (_localName, _value);
}
}
}
private ApiCompatibilityLevel GetAPICompatibilityLevel ()
{
#if !UNITY_5_6_OR_NEWER
return UnityEditor.PlayerSettings.apiCompatibilityLevel;
#else
return UnityEditor.PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.selectedBuildTargetGroup);
#endif
}
This should be available from 2017.1 and newer. Same versions that the new Scripting Runtime has been available.