由于在TestStand和矢量XLDriver (这里用于汽车CAN总线)方面有经验的人可能很少,我真的很欣赏有根据的猜测...
TestStand 2014 64位
我在序列中有一个动作步骤。它使用了一个C#动态链接库的函数。该函数运行良好,但如果我尝试在函数之前插入类范围中的两行中的一行:
public XLDriver xlDriver = new XLDriver();或
private static XLDriver xlDriver = new XLDriver();它在TestStand中不起作用。当从C# Main()调用函数时,后者工作得很好。
在TestStand中,我收到以下内容
An exception occurred inside the call to .NET member 'myMember':
System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei vxlapi_NET.C_XLapiLoader..ctor()
bei vxlapi_NET.XLDriver..ctor()
bei myNameSpace.myClass..ctor() in myFile.cs:Line 27.短语"Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.“可以翻译为“对象引用尚未链接到对象实例”。
如果没有XLDriver行,它就可以在TestStand中工作。在另一个C# Main()中使用它,它仍然可以工作。其他的都没变。
vxlapi_NET.dll调用vxlapi.dll或vxrapi64.dll。由于我已经删除了32位版本并再次尝试,因此vxlapi_NET.dll文件可能不会调用错误的文件。
如果我在另一个使用该C#并编译为可执行文件的C#项目中使用my Dll,我可以在TestStand中使用它。它完美地调用了XL驱动程序。
那么,在TestStand序列步骤中使用可执行文件还是C# Dll有什么区别呢?
谢谢。
发布于 2018-06-06 20:47:33
我重构了vxlapi_NET,问题出在Assembly.GetEntryAssembly()方法中,GetEntryAssembly返回null。
// Decompiled with JetBrains decompiler
// Type: vxlapi_NET.C_XLapiLoader
// Assembly: vxlapi_NET, Version=9.0.0.26263, Culture=neutral,
....
namespace vxlapi_NET
{
internal class C_XLapiLoader
{
private string exeDirectory =
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
....根据.NET NUnit test - Assembly.GetEntryAssembly() is null,您可以使用
/// <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);
}
....
SetEntryAssembly();
XLDriver xlDriver = new XLDriver();
...https://stackoverflow.com/questions/33037263
复制相似问题