I'm receiving an ArgumentException "Object type cannot be converted to target type" but it doesn't make very sense to me.
the method I'm calling has the following signature:
public void Scan(IProgressStatus monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string scanFolder, string[] filesToIgnore)
I tried to pass monitor
instead of remMonitor
but the exception is still thrown.
All the arguments have values except scanFolder
that is null (but passing string.Empty still throw exception) and filesToIgnore
is a zero-length array.
I can't figure out why the exception is thrown.
Don't know if it helps but the process is 64 bit. If I call the same method from a 32 bit process no exception are thrown and it runs well.
[EDIT] If I pass null instead of remMonitor it enters the method.
[EDIT2] Debugging more deeply I found something strange. I've tried to box-unbox the parameter:
rsd.Scan((object)remMonitor, registry.RegistryPath, registry.StartupDirectory, registry.DefaultAddinsFolder, registry.AddinCachePath, scanFolder, filesToIgnore);
and
public void Scan(object monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string scanFolder, string[] filesToIgnore)
{
monitor = (IProgressStatus)monitor;
The result is:
?(IProgressStatus)monitor
Cannot cast 'monitor' (which has an actual type of 'System.Runtime.Remoting.Proxies.__TransparentProxy') to 'Mono.Addins.IProgressStatus'
It looks like that monitor has actually an incompatible type, now the question is why?
[EDIT3] Ok I've managed to understand that it's a DllHell load context problem, I've turn on all the Exceptions inside Visual Studio and it says that Mono.Addins is load in a LoadFrom context. But if I write the instruction Assembly.Load("Mono.Addins");
the same warning (loaded from LoadFrom context) is thrown. Some hints?