当WinCE尝试在.NET CF 2.0中查找另一个异常的消息文本时抛出FileNotFoundException

时间:2012-03-21 20:42:53

标签: c# exception compact-framework .net-2.0 windows-ce

我有一个愚蠢的WinCE应用程序,我只是试图强制异常并从System.SR.dll中获取异常消息,该消息将部署到设备。

我抛出异常的代码如下:

TcpClient client = new TcpClient("abcd", 1234);

但是当SocketException尝试解析它的消息时,它会抛出一个带有以下标记的FileNotFoundException:

  

在System.Reflection.Assembly.InternalGetSatelliteAssembly()   在System.Reflection.Assembly.GetSatelliteAssembly()   在System.Resources.ResourceManager.InternalGetResourceSet()   在System.Resources.ResourceManager.GetString()   在System.Resources.ResourceManager.GetString()   在System.SRSupport.HasString()   在System.SRSupport.HasString()   在System.SR.HasString()   在System.Net.Sockets.SocketException.makeMessage()   在System.Net.Sockets.SocketException..ctor()   在System.Net.Dns.ResolveInternal()   在System.Net.Dns.GetHostEntry()   在System.Net.Sockets.TcpClient.Connect()   在System.Net.Sockets.TcpClient..ctor()   在WinCeMessage.Com.SocketBlaster.Blast()   在WinCeMessage.Form1.button1_Click()   在System.Windows.Forms.Control.OnClick()   在System.Windows.Forms.Button.OnClick()   在System.Windows.Forms.ButtonBase.WnProc()   在System.Windows.Forms.Control._InternalWnProc()   在Microsoft.AGL.Forms.EVL.EnterMainLoop()   在System.Windows.Forms.Application.Run()   在WinCeMessage.Program.Main()

(我相信)保存这些消息的文件是System.SR.dll,当我在Visual Studio中运行它时会将其部署到设备。我停靠了模拟器,并验证了文件是否存在。

这是来自System.SR.dll抛出异常的代码:

internal Assembly InternalGetSatelliteAssembly(CultureInfo culture, Version version, bool throwOnFileNotFound)
{
    if (culture != null)
    {
        Assembly assembly = null;
        AssemblyName name = this.GetName();
        if (name != null)
        {
            name.Version = version;
            name.CultureInfo = culture;
            if (name.Name != null)
            {
                name.Name = string.Concat(name.Name, ".resources");
                name.CodeBase = null;
            }
            try
            {
                StackCrawlMark stackCrawlMark = StackCrawlMark.LookForMyCaller;
                assembly = Assembly.BCL_System_Reflection_Assembly_LoadFromName(name, false, null, ref stackCrawlMark);
            }
            catch (IOException oException)
            {
                assembly = null;
            }
            if (assembly != null)
            {
                if (assembly == this)
                {
                    if (!throwOnFileNotFound)
                    {
                        return null;
                    }
                    else
                    {
                        throw new FileNotFoundException();
                    }
                }
            }
            else
            {
                if (!throwOnFileNotFound)
                {
                    return null;
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }
        }
        return assembly;
    }
    else
    {
        throw new ArgumentNullException();
    }
}

2 个答案:

答案 0 :(得分:1)

我最终制定了一个新的解决方案,因为某种原因,这个解决方案似乎已被打破。

答案 1 :(得分:0)

您是说TcpClient()方法抛出异常并且您无法捕获它?

VS2008的IntelliSense仅显示创建新TcpClient()实例时引发的3个异常:

try {
  TcpClient client = new TcpClient("abcd", 1234);
} catch (ArgumentNullException) {
  Console.WriteLine("ArgumentNullException");
} catch (ArgumentOutOfRangeException) {
  Console.WriteLine("ArgumentOutOfRangeException");
} catch (SocketException) {
  Console.WriteLine("SocketException");
}

在你的例外上放置一个断点。

我的猜测是,您的端口号超出了范围。