2

I'm fairly new to C# and Visual Studio, so I may be missing something basic here, but I couldn't find any solutions.

I was given 2 NET projects, one is an executable which does a few things, but the main bit of code is:

object tempInstance = Activator.CreateInstance(Type.GetTypeFromProgID(progID));

The other project just creates a .dll file, which I've added to the executable in Visual Studio by right-clicking on the 'References' and choosing 'Add Reference...' then browsing for the .dll file that the other project created.

However, I'm having trouble changing the progId in the .dll file. If I leave it as "NETLoginDevice.DemoLoginDevice" it works. I can also change the first part and get "TestMan.DemoLoginDevice" to work. However, I wanted to change it to something like "TestMan.Receiver", but the executable code returns null when it tries to get the type from that progId. Is there something I need to change to get this to work?

I can't find any other reference to "DemoLoginDevice" anywhere in the project, and the top of the class I'm defining looks like:

[ComVisible(true)]
[ProgId("TestMan.Receiver")]
[Guid("6C163B59-CF0F-4C69-B8A6-8D3DBED2640E")]
public class Receiver: IAuthenticationNET, IAuthenticationNETLoginResult

It seems like I should be able to set progID to "TestMan.Receiver" and the executable code should work, but I get an ArgumentNullException instead.

EDIT: I still can't get the Type.GetTypeFromProgID() to work, but if I do:

Type.getTypeFromCLSID(new Guid("6C163B59-CF0F-4C69-B8A6-8D3DBED2640E"));

I can see in the debugger that it gets back a

{Name = "Receiver" FullName = "TestMan.Receiver"}

Just like when I do:

Type.getFromProgId("TestMan.DemoLoginDevice");

I still don't understand where the "DemoLoginDevice" is coming from and why "TestMan.Receiver" doesn't work. I've tried changing the Guid as well (in case things were overwriting each other), but haven't had any luck.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    The DLL needs to be registered, typically with Regasm.exe, you have not told us anything about it. You should not be doing this at all, use a .NET library simply by adding a reference to it. In case you are doing this to test the ComVisibility, do keep in mind that this is not a real test, the CLR shortcuts it. Always perform tests with the plumbing provided by the target language tooling. – Hans Passant Oct 21 '17 at 08:22

0 Answers0