-
Notifications
You must be signed in to change notification settings - Fork 481
Proposal for change: Remove raising exception when Copyright or company assembly attributes are null and set with default values #403
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
Comments
Great write up of the problem. Thanks. Some of these changes revert Viktor's netstandard PR, which is fine... I was never really crazy about just targeting netstandard2.0 given some of the other support for net40 and net45 we've had traditionally. |
Thanks @ericnewton76 |
Hi, I've read all the issue and previous ones related to this, and I wonder if instead of just trying to make unit tests not raising exceptions, it would not be better to allow that even those unit tests scenarios correctly read all the attributes from the right assembly like when running in Production ? And for that I wonder if it would be possible to explicitly give to I've not deep dive in the code of this project but as a consumer I would found reasonable to write something like: public static class Program
{
public static int Main(string[] args)
{
var parser = new Parser(settings => settings.EntryAssembly = typeof(Program).Assembly);
[...]
}
} Like that the entry assembly could be defined by the consumer and this should avoid magical variations between unit tests and production executions, or netframework vs netcoreapp executions, or what else could come later. |
Problem
Test fail in Xunit or Nunit framework in net4x when Copyright or Company assembly attributes are null
Problem Analysis
The problem is existing since version 2.3 and now in v2.4.3 but the behavior is different based on the test project is net4x.
The test fail for the test cases that test --help or --version or even errors for bad options in the commandline
See this issue and issue
and this in NUnit project
These issues can't be detected by the current unit test project because unit test uses the method
SetAttributeOverride' and bypass the
EntryAssemply`The CommandLineParser in Production is running Ok when reading AssemblyAttributes copyright and company, but in Test project in Full Framework net4x or latter it cause the failure of test when reading assembly attributes.
The test is OK in netcoreapp2.x
In production the entryAssemply is the console project itself which have copyright and company assembly attributes
but in test , the executer is the testhost framework itself which has null values for copyright and company assemply attributes.
This because the CommandlineParser raise Exception when CopyRight/Company are null see this
Behavior in v2.3
in net45x or latter: Assembly.GetExecutingAssembly();
in netstandard1.5 or latter: Assembly.GetEntryAssembly()
Behavior in v2.4.3
in netstandrad2.x :Assembly.GetEntryAssembly();
Advantage of removing raising exception
Suggested Solution
PR can modify CopyrightInfo.cs and Headinginfo.cs to remove exception and set default values.
Consideration for Unit Test
GetExecutingOrEntryAssembly
which is under test.Proof of Concept
POC can be done for evaluating this change.
Update
Also, the following code in ReflectionHelper:
can be modified to:
Assembly.GetCallingAssembly Returns the Assembly of the method that invoked the currently executing method
POC
I did the modification of GetExecutingOrEntryAssembly as described in
(GetExecutingOrEntryAssembly)
and modified the test project to multi-target netcoreapp2.0 and net461/net472 and all tests (334 test case) pass successfully in both targets. Also I test the issue 389 and no exception is firedThe text was updated successfully, but these errors were encountered: