1

Since there might be very few people with Experience in TestStand and Vector XLDriver (here used for automotive CAN bus), I would really appreciate educated guesses ...

TestStand 2014 64Bit

I have an Action Step in a Sequence. It uses a function of a C# Dll. The function runs perfectly but if I try to insert one of the two lines in the class scope before the function:

public XLDriver xlDriver = new XLDriver();

or

private static XLDriver xlDriver = new XLDriver();

it doesn't work in TestStand. The latter works fine, when calling the function from a C# Main().

In TestStand I receive the following

 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.

The Phrase "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." can be translated as "The object reference has not been linked to an object instance."

Without that XLDriver line it works in TestStand. Using it in another C# Main() it works anyway. Nothing else changed.

The vxlapi_NET.dll calls the vxlapi.dll or the vxlapi64.dll. Since I already deleted the 32-bit Version and tried again, the vxlapi_NET.dll file might not call the wrong one.

If I use the my C# in another C# Project which uses the Dll and compiles to an executable, I can use it in TestStand. It calls the XL Driver perfectly.

So where is the difference in using an executable or a C# Dll in a TestStand Sequence Step?

Thanks.

Christian
  • 13
  • 5
  • A very similar problem was posted [here](http://forum.unity3d.com/threads/null-exeption-by-use-externel-imported-dll.334723/), but there are no replies. – Christian Oct 09 '15 at 12:06

1 Answers1

0

I refactored vxlapi_NET, problem is in Assembly.GetEntryAssembly() method, GetEntryAssembly returns 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);

  ....

According with .NET NUnit test - Assembly.GetEntryAssembly() is null you may use

     /// <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();
 ...
lison
  • 170
  • 1
  • 6