Reputation: 11
I am a French intern and I got a really big issue so can you help me please :
The goal of my project is to automatize some tests from a .dll coded in VB6 in a C# programs. In fact I use some classes from my VB project which will allow us to prevent regressions in the code. The .dll is in x86 so my C# project.
Here is an example of how I use the dll
using E2S_Equipment;
…
public void verifyEquipmentTextProperty(string eqpCode, bool equipmentIsDynamic, string textPropertyCode, bool textPropertyIsDynamic, string propValue)
{
//Class from E2S_Equipment dll
claEQPSRVReadString readStrService = new claEQPSRVReadString();
readStrService.LoadByKey(eqpCode);
…
}
All my test are in success when I launch them in Visual Studio but when I launch them with Command Line with MSTest the first test is in success and the others are in failure. My error is :
System.Runtime.InteropServices.COMException: Creating an instance of the COM component with CLSID {987C190C-8CFD-4E41-882B-3BAE73768066} from the IClassFactory failed due to the following error: 800a005b Exception from HRESULT: 0x800A005B.
My problem concern the declaration of claEQPSRVReadString
My first thought was that my code created for each test a new instance of the COM Object and so I created a Singleton pattern to have only one instance of my COM component like this:
public static class SrvReadTextPropertySingleton
{
private static claEQPSRVReadString mEqpSrvReadTextProperty;
public static claEQPSRVReadString EqpSrvReadTextProperty
{
get
{
if (mEqpSrvReadTextProperty == null)
{
mEqpSrvReadTextProperty = new claEQPSRVReadString();
}
return mEqpSrvReadTextProperty;
}
}
}
And now I get this error SrvReadTextPropertySingleton. EqpSrvReadTextProperty.LoadByKey(eqpCode);
.
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
So, do you have any idea? Thanks you in advance !
Upvotes: 1
Views: 5356
Reputation: 11
I Found the problem. It's was due link to the Thread Execution.
In the .testsettings file we add :
<Execution>
<ExecutionThread apartmentState="MTA"/>
</Execution>
</TestSettings>
http://ralessi.wordpress.com/2013/09/11/mta-testing-on-vs2012/
Upvotes: 0
Reputation: 3510
Are you 100% sure that your project settings are correct. Your Platform Target should be x86 and the Prefer 32-bit check box should be ticked. Also are you running the Debug version or the release version from the command line. You need to set your 32 bit settings for both environments. For the command line version print out the following to ensure your environment is correct.
Console.WriteLine("OS {0}, Process {1}", System.Environment.Is64BitOperatingSystem, System.Environment.Is64BitProcess);
It may also be useful to keep a reference to the object you are using so that you create it before you use it and then assign it's output value.
var instance = new claEQPSRVReadString();
mEqpSrvReadTextProperty = instance.Value;
Once of course that's possible to access the value that was read from the instance. It looks like it's doing all it's work during the construction phase in the VB6 component, which is a some what an unusual way of doing it. Do you have any other methods to use on the instance that is created.
Upvotes: 1