1

由于可能很少有人在 TestStand 和 Vector XLDriver(这里用于汽车 CAN 总线)方面有经验,我非常感谢有根据的猜测......

测试台 2014 64 位

我在序列中有一个操作步骤。它使用 C# Dll 的功能。该函数运行完美,但如果我尝试在函数之前的类范围中插入两行之一:

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 或 vxlapi64.dll。由于我已经删除了 32 位版本并再次尝试,因此 vxlapi_NET.dll 文件可能不会调用错误的文件。

如果我在另一个使用 Dll 并编译为可执行文件的 C# 项目中使用我的 C#,我可以在 TestStand 中使用它。它完美地调用了 XL Driver。

那么在 TestStand 序列步骤中使用可执行文件或 C# Dll 的区别在哪里?

谢谢。

4

1 回答 1

0

我重构了 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 测试 - Assembly.GetEntryAssembly() 为空 ,您可以使用

     /// <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();
 ...
于 2018-06-06T12:47:33.337 回答