Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:23:33+00:00 2026-06-11T16:23:33+00:00

After installing VS2012 Premium on a dev machine a unit test failed, so the

  • 0

After installing VS2012 Premium on a dev machine a unit test failed, so the developer fixed the issue. When the changes were pushed to TeamCity the unit test failed. The project has not changed other than the solution file being upgraded to be compatible with VS2012. It still targets .net framework 4.0

I’ve isolated the problem to an issue with unicode characters being escaped when calling Uri.ToString. The following code replicates the behavior.

Imports NUnit.Framework

<TestFixture()>
Public Class UriTest

   <Test()>
    Public Sub UriToStringUrlDecodes()
       Dim uri = New Uri("http://www.example.org/test?helloworld=foo%B6bar")

       Assert.AreEqual("http://www.example.org/test?helloworld=foo¶bar", uri.ToString())
    End Sub

End Class

Running this in VS2010 on a machine that does not have VS2012 installed succeeds, running this in VS2010 on a machine with VS2012 installed fails. Both using the latest version of NCrunch and NUnit from NuGet.

Machine without VS2012 Install

Machine with VS2012 Install

The messages from the failed assert are

  Expected string length 46 but was 48. Strings differ at index 42.
  Expected: "http://www.example.org/test?helloworld=foo¶bar"
  But was:  "http://www.example.org/test?helloworld=foo%B6bar"
  -----------------------------------------------------^

The documentation on MSDN for both .NET 4 and .NET 4.5 shows that ToString should not encode this character, meaning that the old behavior should be the correct one.

A String instance that contains the unescaped canonical representation of the Uri instance. All characters are unescaped except #, ?, and %.

After installing VS2012, that unicode character is being escaped.

The file version of System.dll on the machine with VS2012 is 4.0.30319.17929

The file version of System.dll on the build server is 4.0.30319.236

Ignoring the merits of why we are using uri.ToString(), what we are testing and any potential work around. Can anyone explain why this behavior seems to have changed, or is this a bug?

Edit, here is the C# version

using System;
using NUnit.Framework;

namespace SystemUriCSharp 
{
    [TestFixture]
    public class UriTest
    {

        [Test]
        public void UriToStringDoesNotEscapeUnicodeCharacters()
        {
            var uri = new Uri(@"http://www.example.org/test?helloworld=foo%B6bar");

            Assert.AreEqual(@"http://www.example.org/test?helloworld=foo¶bar", uri.ToString());
        }

    }
}

A bit of further investigation, if I target .NET 4.0 or .NET 4.5 the tests fail, if I switch it to .NET 3.5 then it succeeds.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:23:34+00:00Added an answer on June 11, 2026 at 4:23 pm

    The change is related to problems with earlier .NET versions, which have now changed to become more compliant to the standards. %B6 is UTF-16, but according to the standards UTF-8 should be used in the Uri, meaning that it should be %C2%B6. So as %B6 is not UTF-8 it is now correctly ignored and not decoded.

    More details from the connect report quoted in verbatim below.

    .NET 4.5 has enhanced and more compatible application of RFC 3987
    which supports IRI parsing rules for URI’s. IRIs are International
    Resource Identifiers. This allows for non-ASCII characters to be in a
    URI/IRI string to be parsed.

    Prior to .NET 4.5, we had some inconsistent handling of IRIs. We had
    an app.config entry with a default of false that you could turn on:

    which did some IRI handling/parsing. However, it had some problems. In
    particular it allowed for incorrect percent encoding handling.
    Percent-encoded items in a URI/IRI string are supposed to be
    percent-encoded UTF-8 octets according to RFC 3987. They are not
    interpreted as percent-encoded UTF-16. So, handling “%B6” is incorrect
    according to UTF-8 and no decoding will occur. The correct UTF-8
    encoding for ¶ is actually “%C2%B6”.

    If your string was this instead:

            string strUri = @"http://www.example.com/test?helloworld=foo%C2%B6bar";
    

    Then it will get normalized in the ToString() method and the
    percent-encoding decoded and removed.

    Can you provide more information about your application needs and the
    use of ToString() method? Usually, we recommend the AbsoluteUri
    property of the Uri object for most normalization needs.

    If this issue is blocking your application development and business
    needs then please let us know via the “netfx45compat at Microsoft dot
    com” email address.

    Thx,

    Networking Team

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After installing capybara-webkit, I tried to try a test inside a spec, here is
After installing Android SDK tools revision 14 and fixed build.xml I cant build native
After installing the new server, I am facing an issue. I have lot of
After installing the release version of VS2012, I am unable to find SQL CLR
After installing one of my .Net apps on a Windows 7 machine I keep
After installing Test & Performance Tools Platform in Eclipse Ganymede on, whenever I tried
After installing a new build machine, I found out it came with 6.0.10 of
After installing the Developer Preview our Custom FxCop rules project won't build as the
After installing WebMatrix 2 Beta on my development machine, an MVC project compiled on
I'm using Mono.Cecil 0.9.5.3, and after installing VS2012 RC (which causes the .NET 4.0

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.