Showing results for 
Search instead for 
Did you mean: 

Problem with Unit tests for Tecnomatix API




I am developing functions for Process Designer with the Tecnomatix API.

After my development was finished I started writing Unit tests, but as soon as I am using the Tecnomatix API my tests fail due to a “BadImageFormatException”.

I already googled this exceptions and the solution to switch on a “x86 platform” or “x64 platform” didn’t work for me.


Can anyone help me to solve this problem?


Re: Problem with Unit tests for Tecnomatix API

Siemens Legend Siemens Legend
Siemens Legend

For which architecture are you building your assembly? 32 / x64 / Any ?

Which Tecnomatix installation do you use 32/64 bit ?


In general you should use the same architecture as your Tecnomatix installation.


Are you unsing client .NET API or eMServer COM API ?


Can you post a minimal sample of your project, which references you use, etc. ?



Re: Problem with Unit tests for Tecnomatix API


Thanks for your answer!


You are right. Yesterday I already found out, that I am using a 32 bit Tecnomatix on a 64 bit architecture.

For everybody, who is facing the same problem in the future, here are two simple tests to implement detecting if you have the right settings (if the tests fail, just follow the steps in the comments):



       public void ConfigurationTest_Running_64Bit_OS()


           // It was determined to run only in 64 bits.

           bool is64BitOS = System.Environment.Is64BitOperatingSystem;

           Assert.AreEqual(is64BitOS, true);




       public void ConfigurationTest_Running_64Bit_Process()


           // We have a requirement that one of the unmanaged DLL is built for 64 bits.

           // If you are running MS Test in Visual Studio 2013 and this

           // is failing, go to Test->Test Settings->Default Processor Architecture and

           // chose x64, then run the tests again. This is not the only method. You

           // could also use a test settings file.

           bool is64BitProcess = System.Environment.Is64BitProcess;

           Assert.AreEqual(is64BitProcess, true);


Re: Problem with Unit tests for Tecnomatix API


Since my tests are running now, I’m unfortunately facing another problem.

The project I’m working on (also the project I am writing the unit tests for) is to create a .dll file for adding UserLBFunctions.

First a minimal sample of the tests I’m running:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Ressourcenbibliothek.Functions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using System.Collections;

using Tecnomatix.Engineering;


namespace Ressourcenbibliothek.Functions.Tests



   public class BegrenzeWertebereichTests



       public void BegrenzeWertebereichTest_Normal()


           //Set parameters

           ArrayList parameters = new ArrayList();

           parameters.Add(new TxPlcValue().DWordValue = 70);

           parameters.Add(new TxPlcValue().DWordValue = 1);

           parameters.Add(new TxPlcValue().DWordValue = 120);



           TxPlcValue result = new BegrenzeWertebereich().Evaluate(parameters);


           //Check result

           uint expectedresult = 70;







And here is the Error Message I am getting if the compiler reaches the first “TxPlcValue” (sorry, there is still some German in the error message even though I changed the language to English):


Test Name:       BegrenzeWertebereichTest_InOfMinMax

Test FullName:  Ressourcenbibliothek.Functions.Tests.BegrenzeWertebereichTests.BegrenzeWertebereichTest_InOfMinMax

Test Source:            …\VisualStudioProjekte\Ressourcenbibliothek\RessourcenbibliothekTests\Functions\BegrenzeWertebereichTests.cs : line 69

Test Outcome:  Failed

Test Duration:   0:00:00,0152121


Result Message:           Die Ressourcenbibliothek.Functions.Tests.BegrenzeWertebereichTests.BegrenzeWertebereichTest_InOfMinMax-Testmethode hat eine Ausnahme ausgelöst: System.IO.FileLoadException: Eine von "Implementation.Biw.dll" importierte Prozedur konnte nicht geladen werden.

Result StackTrace:       

at Tecnomatix.Engineering.TxPlcValue..ctor()

   at Ressourcenbibliothek.Functions.Tests.BegrenzeWertebereichTests.BegrenzeWertebereichTest_InOfMinMax() in ...\VisualStudioProjekte\Ressourcenbibliothek\RessourcenbibliothekTests\Functions\BegrenzeWertebereichTests.cs:line 72.



The only information the internet provides is that “Siemens PLM Software” is the developer of Implementation.Biw.dll. but no information in combination with Visual Studio development.


Hope that you can also find a solution for this problem.


Thanks again for your time and help!!!



Re: Problem with Unit tests for Tecnomatix API

Siemens Legend Siemens Legend
Siemens Legend

In your Unit Test project you likely reference the Tecnomatix.Engineering assembly (DLL) in which the User LB Func interface is defined.


The Tecnomatix.Engineering assembly is not designed to be loaded standalone, i.e., outside the context of Tune.exe (Process Simulate's framework process) - so it has plenty of dependencies on other DLLs which are pre-loaded and initialized by Tune.exe, but are not by your unit test project. Likely this is the reason why dependent assemblies / DLLs fail to be loaded.


A possible way for you to Unit Test your user function logic is to mock the specific interface without actually loading the assembly.



Re: Problem with Unit tests for Tecnomatix API


Hi Zachi,


thanks for your answer.

I now tried to mock the “TxPlcValue” class since this is the only class I need to test my project. This works (Visual Studio doesn’t show me any red underlines), but as soon as I try to test my User LB Func project, which has the real TxPlcValue loaded, I get an error message that says that the two classes are from different sources and are not compatible.

It is really important for me to test my project to have a complete software development process for my thesis paper. Really hope you can help me finding a way to test my project 'cuz it seems that you have lots of experience with this topic.