简体   繁体   中英

Azure worker host not running .net 4.5.1?

I was testing the Uri.EscapeDataString() method, and expecting the new behavior as stated in http://msdn.microsoft.com/en-us/library/hh367887(v=vs.110).aspx . However when I run this method in a simple Azure worker role (targeted to .NET 4.5.1 and deployed to Windows 2012 R2). It doesn't return the right escaped string. Here is my simple program in WorkerRole.Run method:

public override void Run()
{
  while (true)
  {
    var s = Uri.EscapeDataString("data (test)");
    // This returns "data%20(test)" (.NET 4.0 behavior)
    // However it should return "data%20%28test%29" (.NET 4.5 behavior)
    Thread.Sleep(10000);
    Trace.TraceInformation("Working" + s, "Information");
  }
}

If I ran EspcapeDataString as a console exe, then it escape the chars correctly. Why does it behave differently in the worker host process even the assembly was targeted to .net 4.5.1? How to make it work correctly?

I looked at the Uri class code. I think the problem is Uri.EscapeDataString uses a flag ShouldUseLegacyV2Quirks to determine whether the uri escape should follow RFC 2396 or 3986. It seems this flag is determined by the target framework version of the entry assembly. However in the Azure Wroker Host, it can't determine the framework version probably because it's a native exe, so it falls back to the old behavior even if the executing assembly is targeted to 4.5.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM