Created
April 8, 2019 17:54
-
-
Save moh-hassan/d2b16285da631eefbffb8a2b9e5722f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
In Xunit, NUnit or Test projects, inherit this class to avoid null exception | |
due to null assembly attributes when using CommandLineParser library | |
*/ | |
public class BaseTest | |
{ | |
public BaseTest() | |
{ | |
//in Full Framework NET4x only, because no appdomain in netcore | |
#if NET45|NET461|NET472 | |
/* Preparing test start */ | |
Assembly assembly = Assembly.GetCallingAssembly(); | |
AppDomainManager manager = new AppDomainManager(); | |
FieldInfo entryAssemblyfield = manager.GetType().GetField("m_entryAssembly", BindingFlags.Instance | BindingFlags.NonPublic); | |
entryAssemblyfield.SetValue(manager, assembly); | |
AppDomain domain = AppDomain.CurrentDomain; | |
FieldInfo domainManagerField = domain.GetType().GetField("_domainManager", BindingFlags.Instance | BindingFlags.NonPublic); | |
domainManagerField.SetValue(domain, manager); | |
/* Preparing test end */ | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment