废话参数异常调用的方法 [英] nonsense argument exception calling method

查看:231
本文介绍了废话参数异常调用的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个ArgumentException对象类型无法转换为目标类型,但它并没有做出非常有意义的我。你可以看到除了这个图片

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)

我试图通过监测,而不是 remMonitor ,但除了仍然抛出。 所有的参数都只是 scanFolder 值是空的(但传递的String.Empty还是抛出异常)和 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.

不知道是否有帮助,但这个过程是64位。如果我打电话从32位进程相同的方法也不例外抛出,并运行良好。

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.

如果我通过,而不是remMonitor空进入的方式。

If I pass null instead of remMonitor it enters the method.

调试更深入地我发现了一些奇怪的事情。我试着箱拆箱参数:

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);

public void Scan(object monitor, string registryPath, string startupDir, string addinsDir, string databaseDir, string scanFolder, string[] filesToIgnore)
{
    monitor = (IProgressStatus)monitor;

结果是:

?(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?

确定我已经成功地明白,这是一个DllHell负载范围内的问题,我已经打开所有的Visual Studio中的例外,它说,Mono.Addins是负载在LoadFrom上下文。但是,如果我写的指令的Assembly.Load(Mono.Addins); 同样的警告(从LoadFrom上下文加载)被抛出。一些提示?

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?

推荐答案

最后,我已经成功地解决我的问题:

Finally I've managed to solve my problem:

写在EDIT3这是一个负载范围内的问题,的这个博客解释相当不错每种方法的装载行为。

As written in EDIT3 it was a load context problem, this blog explains quite well the loading behavior for each method.

因此​​,以这暗示我使用手动加载的程序集

Accordingly to this hint I've manually loaded the assembly using:

        System.Reflection.AssemblyName an = new System.Reflection.AssemblyName();
        an.Name = "Mono.Addins";
        an.Version = new System.Version(1, 0, 0);
        System.Reflection.Assembly.Load(an);

然后,我已经放在正确的装配 Mono.Addins.dll AutoCAD.exe 道内(即是 ApplicationBase 我的应用程序)。本来我以为 ApplicationBase 是调用组件的相同的路径,但没有,仅供参考,发现应用程序的基本路径我使用系统。 AppDomain.CurrentDomain.BaseDirectory;

Then I've placed the right assembly Mono.Addins.dll inside the AutoCAD.exe path (that is the ApplicationBase for my application). Originally I thought that the ApplicationBase was the same path of the calling assembly but was not, FYI to discover the Application base path I've used System.AppDomain.CurrentDomain.BaseDirectory;

这篇关于废话参数异常调用的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆