ResolveUrl() from WCF service

I wanted to ResolveUrl() from WCF service and found .
However the function assumes that the call is synchronous, in asynchronous call (e.g called from TPL task) HttpContext.Current==null.
I had to split my asynchronous method into two-a long asynchronous one, invoked as task and generating relative URL and a post-task, that is calling wwWebUtils.ResolveServerUrl(relativeUrL)

The  article suggests to use
but i expect, it wouldn’t work from asynchronous thread as well.

DataContractSerializer truncated string when used with MemoryStream,but works with StringWriter

We’ve used the following DataContractSerializeToXml method for a long time, but recently noticed, that it doesn’t return full XML for a long object, but  truncated it and returns XML string with the length of  multiple-of-1024 , but the reminder is not included.

 internal static string DataContractSerializeToXml<T>(T obj)
string strXml =
Type type= obj.GetType();//typeof(T)
DataContractSerializer serializer = new DataContractSerializer(type);
MemoryStream aMemStr = new System.IO.MemoryStream();
XmlTextWriter writer = new System.Xml.XmlTextWriter(aMemStr, null);
serializer.WriteObject(writer, obj);
strXml = System.Text.
return strXml;

I tried to debug and searched Google for similar problems, but didn’t find explanation of the error. The most closed talking about incorrect length, but not about truncated string.

fortunately replacing MemoryStream to StringWriter according to
fixed the issue.

  1: var serializer = new DataContractSerializer(tempData.GetType());
  2: using (var backing = new System.IO.StringWriter())
  3: using (var writer = new System.Xml.XmlTextWriter(backing))
  4: {
  5:     serializer.WriteObject(writer, tempData);
  6:     data.XmlData = backing.ToString();
  7: }


Convert collections of enums to collection of strings and vice versa

Recently I needed to convert collections of  strings, that represent enum names, to collection of enums, and opposite,  to convert collections of   enums  to collection of  
strings. I didn’t find standard LINQ extensions.
However, in our big collection of helper extensions I found what I needed – just with different names:
/// <summary>
/// Safe conversion, ignore any unexpected strings

/// Consider to name as Convert extension
/// </summary>
/// <typeparam name=”EnumType”></typeparam>
/// <param name=”stringsList”></param>
/// <returns></returns>
public static
List<EnumType> StringsListAsEnumList<EnumType>(this List<string> stringsList) where EnumType : struct, IComparable, IConvertible, IFormattable
List<EnumType> enumsList = new List<EnumType>();
foreach (string sProvider in stringsList)
    EnumType provider;
    if (
EnumHelper.TryParse<EnumType>(sProvider, out provider))
    return enumsList;

/// <summary>
/// Convert each element of collection to string
/// </summary>
/// <typeparam name=”T”></typeparam>
/// <param name=”objects”></param>
/// <returns></returns>
public static
IEnumerable<string> ToStrings<T>(this IEnumerable<T> objects)
return objects.Select(en => en.ToString());