2012-01-02 34 views
2

我需要調用一個FoxPro(VFP 8)的COM對象從C#從.Net調用Visual FoxPro COM對象(進程外)時RPC_E_SERVERFAULT?

VFP的代碼看起來是這樣的:

Define Class x2 As session OlePublic 
    Function testInteropServer() 
    ENDFUNC 
Enddefine 

C#代碼看起來是這樣的:

[TestFixture] 
public class TestFixture 
{ 
    [Test] 
    public void TestXtmBase() 
    { 
     xtmbase.x2 xtmBaseX2 = new xtmbase.x2(); 
     xtmBaseX2.testInteropServer(); 
    } 
} 

的COM服務器被編譯爲一個可執行文件(而不是一個dll)。我可以從Fox加載它。它將對象加載到.Net中,但我似乎無法調用它的任何方法。我通過VS 2005中的GUI導入COM參考。它可以識別對象的所有方法和屬性。我只是無法訪問它們。 我收到以下錯誤:

Test 'TestProject/TestFixture/TestXtmBase' failed: 
    Execute 
    System.Runtime.InteropServices.COMException: The server threw an exception. 
     (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) 
    ErrorCode: -2147417851 
    at xtmbase.x2Class.testInteropServer() 

要刪除它正在與我創建了下面的代碼MT DLL中的一個COM可執行的可能性:

Define Class MTx2 As session OlePublic 
    Function testInteropServer() 
    ENDFUNC 
Enddefine 

然後,我創建了一個控制檯應用程序:

class Program 
{ 
    static void Main(string[] args) 
    { 
     mtx2.mtx2 mtx2 = new mtx2.mtx2(); 
     mtx2.testInteropServer(); 
     Console.WriteLine("Done"); 
    } 
} 

和失敗:

System.Runtime.InteropServices.COMException was unhandled 
Message="The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))" 
Source="Interop.mtx2" 
ErrorCode=-2147417851 
StackTrace: 
    at mtx2.mtx2Class.testInteropServer() 
    at ConsoleTest.Program.Main(String[] args) in E:\development\iisx2\ConsoleTest\Program.cs:line 12 
    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) 
    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
    at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
    at System.Threading.ThreadHelper.ThreadStart() 

任何想法爲什麼?

+0

它是否工作,如果在proc? (可以這樣託管嗎?) – 2012-01-02 04:06:36

+0

'我只是無法訪問它們'當你嘗試時會發生什麼?是否有例外? – 2012-01-02 04:07:35

+1

也許有用(對於RPC_E_SERVERFAULT):http://stackoverflow.com/questions/7066577/com-interop-fails-when-moving-to-new-server,http://stackoverflow.com/questions/5172962/c-互操作只在調試器更新,http://stackoverflow.com/questions/5152943/use-com-class-from-localsystem,http:// stackoverflow。com/questions/973206/hresult-0x80010105-rpc -e-serverfault-questions好像DEP,線程模式等都可以起到一個因素。 – 2012-01-02 04:23:00

回答

0

這是由於DEP(數據執行預防)(感謝pst)這似乎是Foxpro代碼的問題。

您可以手動通過圖形用戶界面的應用程序添加到DEP例外列表,但我需要做這樣的一種編程方法:
HKLM \:

使用註冊表項添加的exe排除列表SOFTWARE \微軟\的Windows NT \ CURRENTVERSION \ AppCompatFlags \圖層
「fullPathToExe」= 「DisableNXShowUI」

如果DEP是激活狀態,你必須重新啓動,使其工作。

1

您正在尋找錯誤的過程中的問題。這是COM服務器在發生異常時崩潰了。 RPC_E_SERVERFAULT錯誤僅僅是一個通知,這是一個非常無用的錯誤,因爲關於異常的所有信息都已丟失。

在運行語句之前,將一個調試器附加到服務器進程,並讓它停止所有異常,以便您可以診斷此錯誤。在用Debug + Exceptions完成的VS中,勾選「Win32 Exceptions」的投擲框。工具+附加到進程。

默認處理當然是非常無益的。你可以在Vista中解決這個問題,並且可以使用IGlobalOptions interface。使用COMGLB_EXCEPTION_HANDLING強制服務器崩潰。這需要在服務器代碼中完成,在我想象的Foxpro中應該是一個問題。

相關問題