卡住了“找不到类型”使用CreateInstance()的错误 [英] Stuck with "Cannot find type" error using CreateInstance()
问题描述
我在C#项目的连接实用程序中尝试使用 .CreateInstance()
,同时序列化XML。 .Unwrap()
用于展开可序列化的返回类型,并获取我正在尝试创建的类型的实例。
I am trying to use .CreateInstance()
in a connection utility in a C# project, while serializing XML. .Unwrap()
is used to unwrap the serializable return type and get an instance of the type I'm trying to create.
String fileToLoad = @"D:\RPMOpen\svnCobra\conversion\aui\Model\bin\Debug\RPM_Model";
String file = Path.GetFileName(fileToLoad);
AbstractResponseMessageData response =
(AbstractResponseMessageData)Activator.CreateInstance(file, responseName).Unwrap();
我的程序集 RPM_Model
@D:\RPMOpen\svnCobra\conversion\aui\Model\bin\Debug\RPM_Model
加载正常,但由于类型 ARC_LOGONRS
in responseName
我收到以下错误:
My assembly RPM_Model
at @"D:\RPMOpen\svnCobra\conversion\aui\Model\bin\Debug\RPM_Model"
loads fine, but as a result of the type ARC_LOGONRS
in responseName
I get the following error:
方法中的错误ConnectUtil.Execute:
无法从程序集RPM_Model,Version = 1.0.0.0加载类型
。ARC_LOGONRS
文化=中立,PublicKeyToken = null
Error in method ConnectUtil.Execute: Could not load type
ARC_LOGONRS
from assemblyRPM_Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
.
现在,这就是为什么我被困在错误上:
1。我 引用错误中指定的程序集。
2。 我的GAC中的任何内容都不会覆盖我的 / Debug中的.dll / / c $ c >文件夹。
3。我确保我有正确的.dll版本。
4。 .dll没有其他的依赖关系。
5。我的项目和.dll都有相同的目标平台。
6。我知道我正好引用了程序集,就好像我把 ARCLOGON_RS
在我的代码中,并将鼠标悬停在上面我看到
Now, this is why I am stuck on the error:
1. I did reference the assembly specified in the error.
2. There is not anything in my GAC overriding the .dll in my /Debug
folder.
3. I have ensured that I have the correct version of the .dll.
4. The .dll has no other dependencies.
5. Both my project and the .dll have the same target platform.
6. I know that I am referencing the assembly properly, as if I place ARCLOGON_RS
in my code and hover over it I see
class RPM.Model.Data.ARCLOGON_RS
class RPM.Model.Data.ARCLOGON_RS
,我可以 f12
专注于查看它的属性。
7。我已经清理并重建了两种解决方案。
8。类型 具有公共默认构造函数,该类是public。
9。。参考节点中的.dll 是。
10。我 将正确的程序集名称作为参数传递。
and I can f12
focus on it to see it's properties.
7. I have cleaned and rebuilt both solutions.
8. The type does have a public default constructor, and the class is public.
9. The .dll is in the reference node.
10. I do have the right Assembly Name passed as a parameter.
我的问题是,如果任何人有任何其他想法,为什么我的项目可能会抛出这个错误,以及我可以如何解决它,因为我已经完全用完了诊断。
My question is if anyone has any other idea as to why my project may be throwing this error, and how I may go about fixing it, as I have completely run out of diagnoses.
非常感谢任何帮助。
推荐答案
将typeName提供给 CreateInstance()
完整的类型。尽管我的错误看起来好像在 RPM.Model.Data
中看起来像我想要的,但显然不是。编辑 responseName
为 RPM.Model.Data.ARC_LOGONRS
而不是简单的 ARC_LOGONRS
是克服错误所必需的。
When supplying the typeName to CreateInstance()
I had to hardcode the full type. Despite my error looking as though it is looking within RPM.Model.Data
as I would like it to, it apparently wasn't. Editing responseName
to be RPM.Model.Data.ARC_LOGONRS
instead of simply ARC_LOGONRS
was all that was necessary to overcome the error.
这篇关于卡住了“找不到类型”使用CreateInstance()的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!