lundi 12 décembre 2016

Type.GetTypeFromCLSID and Type.GetTypeFromProgID get cached result?

My program uses COM drivers from 3rd party. I am trying to implement switching between different driver versions.

First I tried using Interop dlls generated by VS and calling regsvr32 from code. I was able to make calls to drivers via Assembly.Load and reflection, but it seemed that despite the fact that I was calling different Interop libraries I was getting the same version. I tried registering and unregistering libraries via regsvr32 before calling interops and tried making a delay in case regsvr32 works slowly.

In the end I removed interop libraries and decided to work directly with COM. Both versions of drivers have the same CLSID. I ended up with code that just tries to instantiate a COM object and get a property that gets a version value.

while (true)
        {
            var CLSID = new Guid("E4795281-3564-11D4-8E97-0080C87C930A");
            var type = Type.GetTypeFromCLSID(CLSID);
            var obj = Activator.CreateInstance(type);
            object propertyValue = type.InvokeMember("Version", System.Reflection.BindingFlags.GetProperty, null, obj, null);
            Console.WriteLine(propertyValue);
            Console.ReadKey();
        }

I run the program and then try to manually register dlls. No matter how long I wait after registration my program instantiates the version it got at the beginning. If I restart the programm - it gets the last registered version. I see that registry record changes, so I think that there might be some caching issue.

I tried running code in separate AppDomain and recreating it, but it didn't help.

I also tried using Type.GetTypeFromProgID with the same result.

Any suggestions for workaround?





Aucun commentaire:

Enregistrer un commentaire