1

我正在开发的应用程序是一个简单的远程聊天应用程序。

当我尝试运行我的应用程序时遇到此异常。当它谈到加载文件或程序集时,我真的不明白。

“System.Reflection.TargetInvocationException:调用目标引发了异常。---> System.IO.FileNotFoundException:无法加载文件或程序集'客户端,版本 = 1.0.0.0”

try
{
   gt = (Greeting)Activator.GetObject(typeof(Greeting), "tcp://Localhost:7189/Greeting");
   handler = new MessageHandler(OnReceive);
   gt.Sender += handler;
}
catch(Exception ex)
{
   textBox2.Text = ex.ToString();
}

此异常在此行​​引发

gt.Sender += handler;

下面是我的问候课。

[Serializable]
public delegate void MessageHandler(string mymsg);
public class Greeting:MarshalByRefObject
{
    public event MessageHandler Sender;

    public override object InitializeLifetimeService()
    {
        return null;
    }

    public Greeting()
    {
    }

    public void postGreeting(string msg)
    {
        if (Sender != null)
        {
            Sender(msg);
        }
    }
}
4

4 回答 4

1

我假设处理程序是在您的客户端程序集中创建的?当您订阅 Greetings.Sender 事件时,对处理程序的引用将传递给您的服务器程序集。作为服务器端反序列化的一部分,它必须解析处理程序类型。由于它位于客户端程序集中,因此服务器程序集必须可以访问它。

将所有程序集构建到一个共享的调试或发布文件夹中,然后重试。

于 2013-04-03T11:55:52.887 回答
0

使用 microsoft sysinternals 进程监视器的想法对我来说非常有效。我能够看到它正在错误的文件夹中寻找依赖项之一。

于 2013-08-18T11:39:07.010 回答
0

If you experience Could not load file or assembly use the Assembly Binding Log Viewer (on disk called fuslogvw.exe and availbale from the .NET SDK) to find out exactly what your process is actually probing, either in the GAC or your application folder.

A typical logentry will hold info similar to this:

LOG: Processing DEVPATH.
LOG: DEVPATH is not set. Falling through to regular bind.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: graphicfailtest.resources, Version=0.0.0.0, Culture=en-US, PublicKeyToken=null
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft.NET/FrameworkSDK/Samples/Tutorials/resourcesandlocalization/graphic/cs/en-US/graphicfailtest.resources.DLL.

and you can then verify that it loads assemblies from a location you expect, inclusing if it is the correct version.

Probing from the msdn docs.

于 2013-08-18T11:51:30.570 回答
0

使用 microsoft sysinternals 进程监视器,配置该工具来监视您的应用程序的所有文件访问操作,然后您可以看到您的进程正在尝试访问哪些程序集。

于 2013-04-02T17:32:09.633 回答