[Fact]
public void FromXml_NoClassAttribute_ThrowsNullReferenceException()
{
var permission = new XamlLoadPermission(PermissionState.None);
var elem = new SecurityElement("IPermission");
permission.FromXml(elem);
}
- Expected: throws
ArgumentException to match other parse failures
- Actual: throws
NullReferenceException!
Cause
public override void FromXml(SecurityElement elem)
{
if (elem == null)
{
throw new ArgumentNullException(nameof(elem));
}
if (elem.Tag != XmlConstants.IPermission)
{
throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedTag, elem.Tag, XmlConstants.IPermission), nameof(elem));
}
string className = elem.Attribute(XmlConstants.Class);
if (!className.StartsWith(GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))
{
throw new ArgumentException(SR.Get(SRID.SecurityXmlUnexpectedValue, className, XmlConstants.Class, GetType().FullName), nameof(elem));
}
Problem:
string className = elem.Attribute(XmlConstants.Class);
if (!className.StartsWith(GetType().FullName, false, TypeConverterHelper.InvariantEnglishUS))
The className can be null!
ArgumentExceptionto match other parse failuresNullReferenceException!Cause
Problem:
The
classNamecan be null!