I have written a class in C# and marked it ComVisible. I uploaded it to my customer's computer and registered it using RegAsm. But when I try to use it from a Python script, I get an error saying "The system cannot find the file specified." If I replace the name of the class with "ThisDoesNotExist.ReportEngine", the error message is "Invalid class string", which is what I would expect. So, it appears that the Python script found the class name ("CrystalReportsRT2.ReportEngine", in case anyone cares) in the registry, but could not find the DLL file containing that class.
If I was working with an old-fashioned COM object, I could find the class name in the registry, note its CLSID, find the registry entry for that CLSID, and file name from the InProcServer32 key. But for a class registered using RegAsm, the InProcServer32 key only contains the class name and other assembly information. How can I find out what file is being looked for so I can verify its existence? Or do I have to add the assembly into the Global Assembly Cache?
I was trying to get a modified version of an existing library to work. I decided to try a brand-new library. I tried this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RegAsmTest
{
[Guid("E476213F-1D62-408C-B89E-D9A8B4814CE1")]
[ComVisible(true)]
public interface ITest
{
int DoSomething(int input);
}
[Guid("C1E26B60-7D25-4EFE-80E9-F958024E22ED")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
[ProgId("RegAsmTest.Test")]
public class Test : ITest
{
public int DoSomething(int input)
{
MessageBox.Show(string.Format("Input was {}", input));
return input;
}
}
}
And I tried using it from Python:
import win32com.client
try:
TestObject = win32com.client.Dispatch("RegAsmTest.Test")
print ("Object created.")
except Exception as ex:
print ("Failed to create object: " + str(ex))
At first I got "Class not registered". I checked to see if I had "Register for COM Interop" checked, and I hadn't. I checked it. I got another error. (I'm sorry, but I've forgotten which.) I tried running RegAsm with /tlb, and I got "System cannot find the file specified." I tried unregistering the library, and got "Invalid class string" where I would have expected "Class not registered". I tried re-registering without /tlb, and got "System cannot find the file specified".
So, I've got three different errors, and I do not know what sequence of operations or missed operations cause them: Class not registered Invalid class string System cannot find the file specified
What do I have to do?