Skip to content

Commit

Permalink
I get "Sequence contains no matching element" exception while trying …
Browse files Browse the repository at this point in the history
…to load recursively assembly that has c++ project dependencies.

The problem reside in TypeFactory class line 180 or so.
typeDefinition.CustomAttributes.Any(att => att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName)
returns two attributes - UnsafeValueTypeAttribute and NativeCppClassAttribute
typeDefinition FullName looks like .$ArrayType$$$BY0GC@$$CB_W

typeDefinition.Fields has no fields so trying to get them leads to an exception here:
var arrayType = typeDefinition.Fields.First(field => field.Name == "FixedElementField").FieldType;

Stack trace looks like that:
System.InvalidOperationException
Sequence contains no matching element
at System.Linq.ThrowHelper.ThrowNoMatchException()
at System.Linq.Enumerable.First[TSource](IEnumerable1 source, Func2 predicate)
at ArchUnitNET.Loader.TypeFactory.CreateTypeFromTypeReference(TypeReference typeReference, Boolean isStub) in \ArchUnitNET\Loader\TypeFactory.cs:line 188
at ArchUnitNET.Loader.TypeFactory.<>c__DisplayClass7_0.b__0(String s) in \ArchUnitNET\Loader\TypeFactory.cs:line 51
at ArchUnitNET.Loader.RegistryUtils.GetFromDictOrCreateAndAdd[T,TK](TK key, Dictionary2 dict, Func2 createFunc) in \ArchUnitNET\Loader\RegistryUtils.cs:line 21
at ArchUnitNET.Loader.TypeRegistry.GetOrCreateTypeFromTypeReference(TypeReference typeReference, Func2 createFunc) in \\ArchUnitNET\Loader\TypeRegistry.cs:line 24 at ArchUnitNET.Loader.TypeFactory.GetOrCreateTypeFromTypeReference(TypeReference typeReference) in \\ArchUnitNET\Loader\TypeFactory.cs:line 50 at ArchUnitNET.Loader.ArchBuilder.<>c__DisplayClass15_0.<LoadTypesForModule>b__3(TypeDefinition typeDefinition) in \\ArchUnitNET\Loader\ArchBuilder.cs:line 84 at ArchUnitNET.Domain.Extensions.EnumerableExtensions.ForEach[T](IEnumerable1 source, Action1[] actions) in \\ArchUnitNET\Domain\Extensions\EnumerableExtensions.cs:line 21 at ArchUnitNET.Loader.ArchBuilder.LoadTypesForModule(ModuleDefinition module, String namespaceFilter) in \\ArchUnitNET\Loader\ArchBuilder.cs:line 79 at ArchUnitNET.Loader.ArchLoader.LoadModule(String fileName, String nameSpace, Boolean includeDependencies, Boolean recursive, FilterFunc filterFunc) in \\ArchUnitNET\Loader\ArchLoader.cs:line 144 at ArchUnitNET.Loader.ArchLoader.LoadAssembliesRecursively(IEnumerable1 assemblies, FilterFunc filterFunc) in \ArchUnitNET\Loader\ArchLoader.cs:line 205
at Architecture.Tests.ArchUnitExtensions.LoadAssemblyRecursively(ArchLoader loader, String assemblyName)

Signed-off-by: Igor Savchenko <[email protected]>
  • Loading branch information
isavchenko committed Jul 10, 2023
1 parent b6f9473 commit 822bc65
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ArchUnitNET/Loader/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ private ITypeInstance<IType> CreateTypeFromTypeReference(TypeReference typeRefer
return new TypeInstance<IType>(type);
}

if (typeDefinition.CustomAttributes.Any(att =>
att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName))
const string fixedElementField = "FixedElementField";

if (typeDefinition.CustomAttributes
.Any(att => att.AttributeType.FullName == typeof(UnsafeValueTypeAttribute).FullName) &&
typeDefinition.Fields.Any(field => field.Name == fixedElementField))
{
var arrayType = typeDefinition.Fields.First(field => field.Name == "FixedElementField").FieldType;
var arrayTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference(arrayType);
Expand Down

0 comments on commit 822bc65

Please sign in to comment.