Skip to content

Commit

Permalink
Merge pull request #614 from WildernessLabs/feature/better-nolink-mes…
Browse files Browse the repository at this point in the history
…sage

improve messaging around possible missing nolink
  • Loading branch information
adrianstevens authored Feb 13, 2025
2 parents 57ffcfc + d62172e commit ed25169
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Source/Meadow.Core/MeadowOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ private static bool Initialize(string[]? args, IApp? app)
{
if (hardwareProviderType != null)
{
Resolver.Log.Trace($"Searching for 'Create' method in type '{hardwareProviderType.Name}'", MessageGroup.Core);
// because reflection doesn't seem to traverse the type constraints, manually do this trash
var createMethod = hardwareProviderType
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)
Expand All @@ -679,10 +680,18 @@ private static bool Initialize(string[]? args, IApp? app)
if (createMethod != null)
{
Resolver.Log.Trace($"Creating hardware provider '{hardwareProviderType.Name}'", MessageGroup.Core);

// allow using non-public constructors
var provider = Activator.CreateInstance(
hardwareProviderType, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public,
null, null, null);
var ctor = hardwareProviderType.GetConstructor(
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy,
null, Array.Empty<Type>(), null);

if (ctor is null)
{
Resolver.Log.Error($"Cannot find constructor for '{hardwareProviderType.Name}'. Has it been added to the nolink settings?", MessageGroup.Core);
}

var provider = Activator.CreateInstance(hardwareProviderType, true);

Resolver.Log.Trace($"Using hardware provider to create hardware...", MessageGroup.Core);
var hardware = createMethod.Invoke(provider, new object[] { CurrentDevice });
Expand Down

0 comments on commit ed25169

Please sign in to comment.