question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CommandsService.LoadAssembly should not attempt to install modules without a valid constructor.

See original GitHub issue

In the current behavior, if a module has an invalid constructor (e.g. requiring a DiscordSocketClient), the LoadAssembly method will throw an InvalidOperationException and crash.

In some cases, users may intend to have only certain modules use custom constructors, while leaving the rest of their modules default.

Projected Change: If the assembly crawler fails to find a valid constructor for a class, skip over that module, rather than hard-failing.

I can create a fix if this issue is deemed unintended behavior.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Jul 17, 2016

Along with what @khionu and @420foxbot suggested, I think it would also be useful to pass the CommandsService instance in the module constructor. I have to use a static variable to pass it as I need the CommandsService instance to implement a help command, and it was also useful to implement commands to help debug type readers.

The constructors I’d want would probably be something like this:

Module(IDiscordClient client)
Module(CommandsService commands)
Module(IDiscordClient client, CommandsService commands)

As for user feedback on modules failing to load, I’d say issuing a Warning and continuing the load would be the best approach. If an attribute were introduced, it would probably be better to mark classes we don’t want to autoload, rather than classes which should autoload, as it makes it clear we have to explicitly load the module rather than have it load automatically.

0reactions
Auralyticalcommented, Jul 20, 2016

As per Discord convo:

  • Add an opt-out property in the Module attribute to avoid autoloading.
  • Don’t hardcode support for constructor properties (except CommandsService I guess), route everything through an optional simple DI (little more than a user friendly Dictionary<Type, object>)
  • Maybe expose an interface so people can use their own DI if they want
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not allowed to load assembly from network location
I've recently set up a new Windows Server 2012 R2 environment and installed Visual Studio 2012. Now I'm having a problem with multiple...
Read more >
How to: Load Assemblies into the Reflection-Only Context
Code loaded into this context can only be examined; it cannot be executed. This means that objects cannot be created, because constructors ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found