You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fail of NUnit netcoreapp2 test Project that reference other netcoreapp2.0 lib, with the exception :The type initializer threw an exception. ----> System.ArgumentException : author
#354
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.
I have other NUnit Test Project (Project1.Test) which is multi-target project (net45;netcoreapp2.0)
For Test I use dotnet CLI command dotnet test.
I run for both frameworks the following command:
dotnet test
For net45 framework: Test Run Successful
For netcoreapp2.0: Test Fail with an exception:
Failed DefaultSettingTest()
Error Message:
System.AggregateException : One or more errors occurred. (The type initializerfor 'project1.StartUp' threw an exception.)
----> System.TypeInitializationException : The type initializer for 'project1.StartUp' threw an exception.
----> System.ArgumentException : author
Stack Trace:
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result()
..... other messages-----
--- End of stack trace from previous location where exception was thrown ---
at Project1.StartUp.RunOptionsAsync(String[] args) in F:\project1\Program.cs:line 103
--ArgumentException
at CommandLine.Text.CopyrightInfo..ctor(Boolean isSymbolUpper, String author, Int32[] copyrightYears)
at CommandLine.Text.CopyrightInfo.get_Default()
public CopyrightInfo(bool isSymbolUpper, string author, params int[] copyrightYears)
{
if (string.IsNullOrWhiteSpace(author)) throw new ArgumentException("author");
...
}
I find an exception is fired when AuthorAttribute is null.
Suggestion for a solution:
For The CommandLineParaser library to be independent of the initialization of AssemplyAttributes in Unit Test environment in Full Framework or netcoreapp2.x and avoid cause of test failure as described in this issue, I suggest removing this exception from the line and setting a reasonable value:
//if (string.IsNullOrWhiteSpace(author)) throw new ArgumentException("author");
if (string.IsNullOrWhiteSpace(author)) author="<<UnDefined Author>>";
Note:
It's better to avoid throwing exception of any Null assemplyAttributes and initialize it with a suitable default value,e.g., CompanyAssemplyAttribute, CopyWrightAssemplyAttributes
The text was updated successfully, but these errors were encountered:
moh-hassan
changed the title
Fail of NUnit netcoreapp2 Test Project that reference other netcoreapp2.0 lib which depends on CommandLineParaser, with the exception :The type initializer for 'project1.StartUp' threw an exception. ----> System.ArgumentException : author
Fail of NUnit netcoreapp2 test Project that reference other netcoreapp2.0 lib using CommandLineParaser, with the exception :The type initializer threw an exception. ----> System.ArgumentException : author
Oct 27, 2018
moh-hassan
changed the title
Fail of NUnit netcoreapp2 test Project that reference other netcoreapp2.0 lib using CommandLineParaser, with the exception :The type initializer threw an exception. ----> System.ArgumentException : author
Fail of NUnit netcoreapp2 test Project that reference other netcoreapp2.0 lib, with the exception :The type initializer threw an exception. ----> System.ArgumentException : author
Oct 27, 2018
I have discussed that issue with NUnit team and no solution is available because the behavior of testhost.dll , the details here
The issue can be resolved by injecting Fake AssemplyAttributes before running test.
That can be done if the method ReflectionHelper.SetAttributeOverride() is available for test project.
Currently, it's private and used internally for CommandLine.Test project.
Kindly, can you set the static class ReflectionHelper public in the next release.
I have multi-target project (Project1) (net45;netcoreapp2.0) that reference CommandLineParaser library.
Project1 have a static class StartUp with a property:
The project is working fine for both frameworks
I have other NUnit Test Project (Project1.Test) which is multi-target project (net45;netcoreapp2.0)
For Test I use dotnet CLI command
dotnet test
.I run for both frameworks the following command:
For net45 framework: Test Run Successful
For netcoreapp2.0: Test Fail with an exception:
What is the root problem:
When I investigated CopyrightInfo class,
I find an exception is fired when AuthorAttribute is null.
Suggestion for a solution:
For The CommandLineParaser library to be independent of the initialization of AssemplyAttributes in Unit Test environment in Full Framework or netcoreapp2.x and avoid cause of test failure as described in this issue, I suggest removing this exception from the line and setting a reasonable value:
Note:
It's better to avoid throwing exception of any Null
assemplyAttributes
and initialize it with a suitable default value,e.g.,CompanyAssemplyAttribute, CopyWrightAssemplyAttributes
The text was updated successfully, but these errors were encountered: