我需要調用一個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()
任何想法爲什麼?
它是否工作,如果在proc? (可以這樣託管嗎?) – 2012-01-02 04:06:36
'我只是無法訪問它們'當你嘗試時會發生什麼?是否有例外? – 2012-01-02 04:07:35
也許有用(對於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