gpt4 book ai didi

.NET NUnit 测试 - Assembly.GetEntryAssembly() 为 null

转载 作者:行者123 更新时间:2023-12-02 03:42:55 26 4
gpt4 key购买 nike

当使用 Assembly.GetEntryAssembly() 的类在单元测试中运行时,Assembly.GetEntryAssembly()null

在单元测试期间是否有一些选项如何定义Assembly.GetEntryAssembly()

最佳答案

实现

中给出的 SetEntryAssembly(Assembly assembly) 方法

http://frostwave.googlecode.com/svn-history/r75/trunk/F2DUnitTests/Code/AssemblyUtilities.cs

到您的单元测试项目。

         /// <summary>
/// Use as first line in ad hoc tests (needed by XNA specifically)
/// </summary>
public static void SetEntryAssembly()
{
SetEntryAssembly(Assembly.GetCallingAssembly());
}

/// <summary>
/// Allows setting the Entry Assembly when needed.
/// Use AssemblyUtilities.SetEntryAssembly() as first line in XNA ad hoc tests
/// </summary>
/// <param name="assembly">Assembly to set as entry assembly</param>
public static void SetEntryAssembly(Assembly assembly)
{
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);
}

关于.NET NUnit 测试 - Assembly.GetEntryAssembly() 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4337201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com