2014-10-19 70 views
0

我正在嘗試製作Nim遊戲,其中邏輯發生在服務器上,客戶端提供遊戲以在.NET Remoting中變得更好。 我有一個DLL我從這個類庫內置:'System.IO.FileNotFoundException'類型的未處理異常 - Dll&remoting

namespace Nim_Common 
{ 
    public interface computerCommon 
    { 
     int[] startGame(int columnNumber); 
     int[] computeTurn(int[] penStatus); 
     bool checkWin(); 
    } 
} 

該DLL我添加作爲參考,我的客戶項目,我的服務器項目,將DLL添加到每個項目的bin/Debug目錄。

這是我的客戶端代碼的相關部分:

using Nim_Common; 

namespace Nim 
{ 
    public partial class Form1 : Form 
    { 
      private computerCommon computerServerHandler; 
      ... 
public Form1() 
     { 
      InitializeComponent(); 
      computerToolStripMenuItem.Select(); 
      newColumnNumber = -1; 
      RemotingConfiguration.Configure("client.exe.config"); 
      computerServerHandler = (computerCommon)Activator.GetObject(typeof(computerCommon), "http://localhost:1234/_Server_"); 
      StartGame(this, null); 
     } 
private void StartGame(object sender, EventArgs e) 
     { 
      int max = 0; 
      if(columns != null) 
       for (int i = 0; i < columns.Length; i++) Controls.Remove(columns[i]); 
      int[] temp = computerServerHandler.startGame(newColumnNumber); 
      columns = new Column[temp.Length]; 
      ... 
     } 

而在服務器部分:

using Nim_Common; 

namespace Nim_Server 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 
     private void Form1_Load(object sender, EventArgs e) 
     { 
      RemotingConfiguration.Configure("server.exe.config"); 
     } 
    } 

    class ServerPart : MarshalByRefObject, computerCommon 
    { 
     ... 

     public ServerPart() 
     { 
      ... 
     } 
     public int[] startGame(int columnNumber) 
     { 
      ... 
     } 
     public int[] computeTurn(int[] penStatus) 
     { 
      ... 
     } 

     public bool checkWin() 
     { 
      ... 
     } 
    } 
} 

server.exe.config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.runtime.remoting> 
    <application> 
     <channels> 
     <channel ref="http server" port="1234" /> 
     </channels> 
     <service> 
     <wellknown mode ="SingleCall" type="Nim_Server.ServerPart, Nim_Server" objectUri="_Server_" /> 
     </service> 
    </application> 
    </system.runtime.remoting> 
</configuration> 

client.exe .config:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> 
    </startup> 
    <system.runtime.remoting> 
    <application> 
     <channels> 
     <channel ref="http client" /> 
     </channels> 

     <client> 
     <wellknown type="Nim_Common.computerCommon, Nim_Common" url="http://localhost:1234" /> 
     </client> 
    </application> 
    </system.runtime.remoting> 
</configuration> 

如果有問題,我的防火牆關閉。 編譯時一切都很好,服務器運行良好。當客戶端到達這條線,就拋出異常:

int[] temp = computerServerHandler.startGame(newColumnNumber); 

例外情況是這樣的:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll 

Additional information: Could not load file or one of its dependencies, the system could not find "Nim_Common". // This is shown in my native language so I'm improvising a bit with the translation. 

這是怎麼回事,如何解決這一問題?

謝謝。

回答

0

我從我自己編譯的dll中收到了這個錯誤。原來我在AssemblyInfo.cs文件中填入了AssemblyCultureAttribute。該項目沒有問題構建,但在使用時不會加載任何引用的項目。

根據MSDN:

把在裝配此屬性,並使用比空字符串(「」)的文化名以外的東西會使本屆大會看起來像一個衛星組件,而不是主包含可執行代碼的程序集。使用該屬性標記傳統的代碼庫將會破壞它,因爲沒有其他代碼能夠在運行時找到庫的入口點。

相關問題