Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Edited Unassigned: NullReferenceException caused by AttributeBasedFormatter on Mono 3.0.6 [12487]

$
0
0
```
(true).Should().BeFalse();
```

results in

```
System.NullReferenceException : Object reference not set to an instance of an object

at FluentAssertions.Formatting.AttributeBasedFormatter.<FindCustomFormatters>b__4 (System.Type type) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectManyIterator>c__Iterator29`3[System.Type,System.Reflection.MethodInfo,<>f__AnonymousType0`2[System.Type,System.Reflection.MethodInfo]].MoveNext () [0x00059] in /private/tmp/source/bockbuild/profiles/mono-mac-release/build-root/mono-3.0.6/_build/mono-3.0.6.git/mcs/class/System.Core/System.Linq/Enumerable.cs:2335
```

Obviously, AttributeBasedFormatter.GetExportedTypes(Assembly) sometimes returns an array that contains null references in Mono, because a ReflectionTypeLoadException is thrown whose Types property contains some null values.

We can easily fix that in AttributeBaseFormatter.FindCustomFormatters():

```
IEnumerable<MethodInfo> source =
from type in AttributeBasedFormatter.AllTypes
where type != null // FIX
from method in type.GetMethods(24)
where method.get_IsStatic()
where method.HasAttribute<ValueFormatterAttribute>()
where method.GetParameters().Count<ParameterInfo>() == 1
select method;
return source.ToArray<MethodInfo>();
```



Viewing all articles
Browse latest Browse all 1402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>