1

ActiveX オブジェクトを閉じてから開き直そうとしていますが、何かが残っていて、エラーが発生しているようですAttempted to read or write protected memory. This is often an indication that other memory is corrupt.。奇妙なことに、動作するオブジェクトのサンプル コードがあり、同じコマンドをすべて呼び出しています。 . サンプル コードはテスト UI を表示するだけなので、私のコードは同一ではありませんが、横に並んだ 2 台のコンピューターでコードとサンプル コードの実行を追跡しました。私は途方に暮れています。

次のようにオブジェクトを閉じます。

        result = result && wrapper.Logout();            

        //  Throw the wrapper in the trash
        IsSelection = false;
        Controls.Remove(wrapper);
        wrapper.Dispose();
        wrapper = null;

再作成すると、既に初期化されていると主張されますが、これはテスト コードでも発生します。再度ログインしようとすると、次のエラーが発生します。

                result = wrapper.Login(Username, Password, Settings.AuthenticationSource, "", "");
                if (!result)
                    GetLastErrorCode();

ラッパーはまさにそれです。実際の通信コードをラップします。ログインは次のようになります。

return (bool)ocx.GetType().InvokeMember("Login", BindingFlags.InvokeMethod, null, ocx, new object[] { userName, password, authSource, token, mnemonic });

ログアウトは次のようになります。

return (bool)ocx.GetType().InvokeMember("Logout", BindingFlags.InvokeMethod, null, ocx, null);

私のコードでは、ActiveX オブジェクトを再作成した後、破棄する前に追加した値を確認できます。その破壊を終わらせるために何かをしているわけではないことはわかっていますが、それが何であるかはわかりません。私が行方不明になっている可能性があることは明らかですか?追加のコードが役立つ場合は、その内容をお知らせください。投稿してみます。

ActiveX オブジェクトのコードにアクセスできないことに注意してください。

よろしくお願いいたします。

編集:

エラーテキストは次のとおりです。

------ Exception ------
Error:  Exception has been thrown by the target of an invocation.
Error:  Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
There was an error logging in to iSite.
Exception has been thrown by the target of an invocation.

   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at ...Login(String userName, String password, String authSource, String token, String mnemonic) in ...:line 375
   at ...Login() in ...:line 500
---- End Exception ----

編集2:

オブジェクトが作成されるコードは次のとおりです。

    System.ComponentModel.ComponentResourceManager resources = 
        new System.ComponentModel.ComponentResourceManager(typeof(xForm));
    try
    {
        wrapper = new xWrapper(Settings.ProgramID, Settings.ActiveXClassID);
    }
    catch (Exception e)
    { ... }

    //  Initialize the wrapper with default settings.
    ((System.ComponentModel.ISupportInitialize)(this.wrapper)).BeginInit();
    ...
    ((System.ComponentModel.ISupportInitialize)(this.wrapper)).EndInit();

    if (wrapper.SupportsPluginMessagingInterface())
    {
        wrapper.PluginMessage -= new xWrapper.
            _MessagingEvents_EventPluginMessageEventHandler(OnMessageReceived);
        wrapper.PluginMessage += new xWrapper.
            _MessagingEvents_EventPluginMessageEventHandler(OnMessageReceived);
    }

    GetLastErrorCode();

ラッパー コンストラクターは単なる既定のコンストラクターですが、後で次のコードを使用して initialize を呼び出します。

return (bool)ocx.GetType().InvokeMember("Initialize", BindingFlags.InvokeMethod, null, ocx, null);

イベント ハンドラーのサブスクライブを解除するコードを追加しましたが、違いはありませんでした。

4

0 に答える 0