简体   繁体   English

Activator.CreateInstance 上的 MissingMethodException

[英]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.

相关问题 Activator.CreateInstance MissingMethodException - Activator.CreateInstance MissingMethodException Activator.CreateInstance期间缺少MissingMethodException - MissingMethodException during Activator.CreateInstance Activator.CreateInstance在1个解决方案中引发MissingMethodException,但在另一个解决方案中不引发 - Activator.CreateInstance throws MissingMethodException in 1 solution but not another 如何修复Activator.CreateInstance失败与MissingMethodException“未找到类型的构造函数”? - How to fix Activator.CreateInstance failing with MissingMethodException “Constructor on type not found”? 使用CoreCLR时Activator.CreateInstance抛出&#39;System.MissingMethodException&#39; - Activator.CreateInstance throws 'System.MissingMethodException' when using CoreCLR Activator.CreateInstance - MissingMethodException:找不到类型为“xxx”的构造函数 - Activator.CreateInstance - MissingMethodException: Constructor on type 'xxx' not found Activator.CreateInstance 找不到构造函数 (MissingMethodException) - Activator.CreateInstance can't find the constructor (MissingMethodException) Activator.CreateInstance() - Activator.CreateInstance() Singleton与Activator.CreateInstance - Singleton with Activator.CreateInstance Activator.CreateInstance() 的用法 - Usage of Activator.CreateInstance()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM