2

WCF サービスで C++ (アンマネージ) ライブラリを参照すると、非常に奇妙な問題が発生します。

ここにコードがあります

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using VarSpace.Elaboration.Operations.ManagedWrapper; //Unmanaged c++ namespace
using CustomILException;

namespace ILCommonLibrary.Core
{
/// <summary>
/// Singleton class to obtain a unique-per thread instance of a WPC Core Client.
/// </summary>
public class WPCCoreClient
{
    private static readonly Object objLock = new Object();
    private readonly Client managedWrapperClient= null; //class coming from C++
    private static volatile WPCCoreClient theInstance;

    private WPCCoreClient() 
    {
        managedWrapperClient=  new VarSpace.Elaboration.Operations.ManagedWrapper.Client();
    }

    /// <summary>
    /// <exception cref="CustomILException.CoreException">Core internal error.</exception>
    /// </summary>
    /// <returns></returns>
    public static WPCCoreClient createInstance() 
    {
         if (theInstance == null) {
             try {
                 lock (objLock) 
                 {
                    theInstance = new WPCCoreClient(); // HERE I HAVE THE ERROR**
                 }
             } catch (VarSpace.Localization.ManagedWrapper.CoreException ex) {
                 // error in configuratorView usage 
                 throw ErrorManagement.setException(new CustomILException.CoreException(ex.Message),
                            ErrorCodes.ERR_CORE_CLIENT_ERROR,
                            "WPCCoreClient.createInstance",
                            String.Format("ConfiguratorClient creation error.")
                            );
             }
         }

         return theInstance;
    }

    /// <summary>
    /// Make an elaboration request to the WPC core system.
    /// Manages a request that has any related output data.
    /// </summary>
    /// <param name="requestXml">xml elaboration input description</param>
    /// <param name="timeOut">request timeout in milliseconds.</param>
    /// <param name="error">output parameter to obtain a string description of the error.</param>
    /// <returns>a boolean to indicate if execution has been correcly executed or not.</returns>
    /// 
    public bool sendRequestToWPC(string requestXml, int timeOut, ref string error)
    {
        bool success;
        int idRequest= 0; /* WPC core id of the request elaboration */

        error = string.Empty;
        DataTable transactionMessages;
        using (transactionMessages = new DataTable())
        {
            try
            {
                success = this.managedWrapperClient.ExecuteRequest(requestXml, timeOut, ref idRequest, transactionMessages);
                if (!success)
                {
                    if (transactionMessages.Rows.Count > 0)
                    {
                        error = "Error code: " + transactionMessages.Rows[0].Field<int>("nCode") +
                                "Error severity: " + transactionMessages.Rows[0].Field<int>("nSeverity") +
                                "Message: " + transactionMessages.Rows[0].Field<string>("nvcMsgText");
                    }
                    else
                    {
                        error = SchedulerRequestError.GetErrorMessage(idRequest);
                    }
                }
            }
            catch (Exception e)
            {
                error = e.Message;
                return false;
            }
        } 
        return success;
    } // method end

} // class end
} // namespace end 

エラーは次のとおりです。

{"'' の型初期化子が例外をスローしました。"}

{"ネストされた例外が、C++ モジュールのロード失敗の原因となった主な例外の後に発生しました。\n"}

   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal (Int32 errorCode、IntPtr errorInfo) で
   .DoCallBackInDefaultDomain (IntPtr 関数、Void* cookie) で
   .DefaultDomain.Initialize() で
   .LanguageSupport.InitializeDefaultAppDomain (LanguageSupport*) で
   .LanguageSupport._Initialize (LanguageSupport*) で
   .LanguageSupport.Initialize (LanguageSupport*) で

最も奇妙なことは、コンソール アプリケーションでこの関数を呼び出すと、機能することです!!!

それはWCFサービスに関連するものですが、どこで確認すればよいか本当にわかりません。私はたくさんの試みをしました。

誰かが私を助けることができますか?

ありがとうございました!

4

0 に答える 0