Uri.UnescapeDataString不同的计算机上失败 [英] Uri.UnescapeDataString fails on different computer

查看:647
本文介绍了Uri.UnescapeDataString不同的计算机上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开发的计算机一切工作很好,很正常,但是当我测试的程序不同的Windows7电脑上我得到一个 System.UriFormatException 无效的URI :有是字符串中一个无效的序列的在下面的代码: Uri.UnescapeDataString(部分);

On my dev computer everything was working fine and dandy but when I tested the program on a different Windows7 computer I was getting a System.UriFormatException: Invalid URI: There is an invalid sequence in the string. On the following code: Uri.UnescapeDataString(section);

起初我以为第二台计算机从开发PC接收不同的数据,所以我复制的是未能文件的HTML字符串和我的代码减少到这一点:

At first I thought the second computer was receiving different data from the dev pc, so I copied the html string that was failing to a file and reduced my code to this:

static void Err(string s){/*Picked up by external logging*/}

private static void GetValue()
{
    try
    {
        var html = File.ReadAllText("ld.txt");

        //Retrieve section we want
        var section = Regex.Match(
            html,
            "etc_etc(.*): ",
            RegexOptions.Singleline)
                                .Groups[1].ToString();

        Uri.UnescapeDataString(section);
    }
    catch (Exception ex)
    {
        Err(ex.ToString());
    }
}



工作罚款dev的电脑,但第二台电脑再次接收该异常。他们都来自完全相同的 ld.txt 文件加载完全相同的HTML,然后做同样的事情与它..和在PC的64位都是Win7的。是什么给了?

Works fine on the dev pc, but the second computer receives the exception again. They're both loading the exact same html from the exact same ld.txt file and then doing the exact same thing with it.. and both PC's are x64 Win7. What gives?

推荐答案

出现UnescapeDataString CLR 4.0和4.5

UnescapeDataString appears to have changed between CLR 4.0 and 4.5

我可以重现这两台机器上安装(即使编译为面向.NET 4.0)不同版本的.NET。

I can reproduce this on two machines with different versions of .Net installed (even though compiled to target .Net 4.0).

你也许有VS 2012你的开发机(因此.NET 4.5),只是在其他计算机上的.Net 4?

Do you perhaps have VS 2012 on your dev machine (and therefore .Net 4.5) and just .Net 4 on the other computer?

这代码抛出的.NET 4.0个例外,传递.NET 4.5

This code throws an exception on .Net 4.0, passes on .Net 4.5

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("CLR version: " + Environment.Version);
        Console.WriteLine(Uri.UnescapeDataString("%"));
    }
}

这篇关于Uri.UnescapeDataString不同的计算机上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆