[英]MissingMethodException on Activator.CreateInstance
I'm trying to create an instance of a foreign DLL.我正在尝试创建一个外国 DLL 的实例。 Unfortunately I get the error message "MissingMethodException".不幸的是,我收到错误消息“MissingMethodException”。 The command Activator.CreateInstance produces this error.命令 Activator.CreateInstance 会产生此错误。
The creation:创作:
Assembly lAssembly =
Assembly.Load(File.ReadAllBytes(@"C:\Siemens.Engineering.dll"));
Type lType = lAssembly.GetType("Siemens.Engineering.TiaPortal", true, true);
return (dynamic)Activator.CreateInstance(type: lType,
args: new object[] {
Siemens.Engineering.TiaPortalMode.WithoutUserInterface
});
the definition of the dll (abbreviated): dll(简称)的定义:
namespace Siemens.Engineering {
//
// Zusammenfassung:
// TIAPortal.
[DebuggerNonUserCode]
[SecuritySafeCritical]
public sealed class TiaPortal : IApplicationEntryPoint,
IInternalApplicationAccess,
IInternalObjectAccess,
IInternalInstanceAccess,
IInternalBaseAccess,
IEngineeringRoot,
IEngineeringObject,
IEngineeringCompositionOrObject,
IEngineeringInstance,
IEngineeringServiceProvider,
IServiceProvider,
IEquatable<object>,
IDisposable
{
//
// Zusammenfassung:
// Initializes a new instance of the
// Siemens.Engineering.TiaPortal class.
//
// Parameter:
// tiaPortalMode:
// TIA-Portal will start in this mode.
[SecuritySafeCritical]
public TiaPortal(TiaPortalMode tiaPortalMode =
TiaPortalMode.WithoutUserInterface);
}
}
I don't know what I'm doing wrong with this call.我不知道我在打这个电话时做错了什么。 Since the constructor has an optional parameter, it should be able to be called with and without parameters.由于构造函数有一个可选参数,它应该可以带参数和不带参数调用。 But both variants produce the same error.但是两种变体都会产生相同的错误。 The assembly (lAssembly), as well as the type (lType), can be loaded correctly.可以正确加载程序集 (lAssembly) 以及类型 (lType)。
Any advice?有什么建议吗?
I found the problem.我发现了问题。 The addressed DLL is looking for a hard-coded path.寻址的 DLL 正在寻找硬编码路径。 If this does not exist, the same cannot be instantiated.如果这不存在,则无法实例化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.