Skip to content

Conversation

@xAiluros
Copy link

When running from something like 'execute-assembly', Environment.Exit can be problematic.

In my code I had something like the following in place: https://www.mdsec.co.uk/2020/08/massaging-your-clr-preventing-environment-exit-in-in-process-net-assemblies/
But you can imagine that when Environment.Exit is used to break an infinite loop, this will get interesting 😄 In this case the monitor action became an infinite loop until negative time remaining gave exceptions.

There are some more uses of Environment.Exit() but they seem less problematic (need to be careful with correct parameters though).

@xAiluros
Copy link
Author

oops - I should read existing PR's first :o

@xAiluros xAiluros changed the title Remove Environment Exit from Harvester Remove Environment.Exit Jul 17, 2023
key = Helpers.StringToByteArray(arguments["/keyhex"]);
try
{
key = Helpers.StringToByteArray(arguments["/keyhex"]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of putting the try/catch around the single function call, would it not be cleaner to have a higher level try block in Main for ArgumentException?

{
try
{
hashBytes = Helpers.StringToByteArray(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comments regarding propagating the exception and catching higher up in Main

{
try
{
hashBytes = Helpers.StringToByteArray(hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@CCob
Copy link
Contributor

CCob commented Jul 21, 2024

Thanks for the PR an sorry for the delay. Finally had some time to look at this. I've added some comments to the PR. I think throwing an ArgumentException is definitely the right approach but I think it needs to be caught higher up in main. That way the multiple instances of try/catch around the Helpers.StringToByteArray can be removed with just a singe one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants