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

"Sequence contains no matching element" while trying to load recursively assembly that has c++ dependencies #218

Merged
merged 6 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ArchUnit.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
9 changes: 6 additions & 3 deletions ArchUnitNET/Loader/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ 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 arrayType = typeDefinition.Fields.First(field => field.Name == fixedElementField).FieldType;
var arrayTypeInstance = GetOrCreateStubTypeInstanceFromTypeReference(arrayType);
var dimensions = new List<int> { 1 };

Expand Down
13 changes: 13 additions & 0 deletions ArchUnitNETTests/ArchUnitNETTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,22 @@
</ItemGroup>

<ItemGroup>
<None Update="Dependencies\cpplib\CppDllTest.dll">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="Domain\PlantUml\zzz_test_version_with_errors.puml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Dependencies\cpplib\" />
</ItemGroup>

<ItemGroup>
<Reference Include="CppDllTest">
<HintPath>Dependencies\cpplib\CppDllTest.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
53 changes: 53 additions & 0 deletions ArchUnitNETTests/Dependencies/CppDependenciesTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2019 Florian Gather <[email protected]>
// Copyright 2019 Fritz Brandhuber <[email protected]>
// Copyright 2020 Pavel Fischer <[email protected]>
//
// SPDX-License-Identifier: Apache-2.0
//

using ArchUnitNET.Domain;
using ArchUnitNET.Domain.Extensions;
using ArchUnitNET.Loader;
using Xunit;

namespace ArchUnitNETTests.Dependencies
{
public class CppDependenciesTests
{
private static readonly Architecture Architecture = new ArchLoader()
.LoadAssembliesRecursively(new[] { typeof(CppExampleClassUser).Assembly },
filterFunc => FilterResult.LoadAndContinue)
.Build();

[Fact]
public void CppClassUserFound()
{
var exampleCppUser = Architecture.GetClassOfType(typeof(CastClassA));
Assert.Contains(exampleCppUser, Architecture.Classes);
}
}

internal class CppExampleClassUser
{
CppExampleClass _cppExampleClass = new CppExampleClass();
}

/*
* C++/CLI code contains the next .h .cpp content
CppExampleClass.h
#pragma once
public ref class CppExampleClass
{
public:
void DoCall();
};

CppExampleClass.cpp
#include "pch.h"
#include "CppExampleClass.h"

void CppExampleClass::DoCall()
{
}
*/
}
Binary file not shown.