пятница, 5 августа 2011 г.
среда, 12 января 2011 г.
WPF - create DataTemplate from FrameworkElement
I'm not quite sure if it works in all cases, but it does work for Canvas.
DataTemplate GetElementAsTemplate(FrameworkElement element) {
StringBuilder builder = new StringBuilder();
builder.AppendFormat(
"
XamlWriter.Save(element));
using(MemoryStream stream = new MemoryStream()) {
using(StreamWriter writer = new StreamWriter(stream)) {
writer.Write(builder.ToString());
writer.Flush();
stream.Position = 0;
DataTemplate template = (DataTemplate)XamlReader.Load(stream);
return template;
}
}
}
воскресенье, 14 ноября 2010 г.
Client HTTP Stack: HttpWebRequest and non-ASCII characters in HTTP response headers
Client HTTP Stack in Silverlight seems to bee too strict sometimes. I have an OOB application that uses HttpWebRequest object to get data from external web service.
Unfortunately, HTTP response from the service includes header that contains non-ASCII characters. And it turns out to be a problem. See code snippet below:
void GetResponseCallback(IAsyncResult ar) {
HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
WebResponse response = request.EndGetResponse(ar);
// code continues …
}
EndGetResponse() call results in System.ArgumentException: Specified value has invalid Control characters. Parameter name: value.
I’m not sure whether it is a bug or designed behaviour. But it’s a pity that invalid header prevents application from obtaining response at all. In fact I don’t even need that header, so my workaround was to switch to browser http handling so that I can move on.
And just for the record: the same code works fine in WPF application.
среда, 10 ноября 2010 г.
Silverlight OOB applications and HTTP handling
With Silverlight, you can specify whether the browser or the client provides HTTP handling for your Silverlight-based applications. By default, HTTP handling is performed by the browser and you must opt-in to client HTTP handling.
Surprisingly, despite of what your intuition might suggest, Silverlight out of browser applications use browser HTTP handling by default. At least for WCF service calls :)
вторник, 14 сентября 2010 г.
Redirecting Error Messages from Command Prompt
dir file.xxx 1> output.msg 2>&1
Knowledge base article: KB110930.
вторник, 22 июня 2010 г.
WinDbg: dumping the target object of a WeakReference
The following example demonstrates how to dump the target object of a WeakReference.
1. Find WeakReference’s object address. In my example it is 0bb9a878.
2. Use !dumpobj to print content of the WeakReference:
0:025> !dumpobj 0bb9a878
Name: System.WeakReference
MethodTable: 5ec0d7ec
EEClass: 5e7eacd8
Size: 16(0x10) bytes
File: C:\Program Files\Microsoft Silverlight\4.0.50524.0\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
5ec0c5a0 4000522 4 System.IntPtr 1 instance 7631528 m_handle
5ec007e4 4000523 8 System.Boolean 1 instance 0 m_IsLongReference
3. The m_handle member is a pointer to the target object. The member is value type (System.IntPtr), so we use !dumpvc command to print its content:
0:025> !dumpvc 5ec0c5a0 7631528
Name: System.IntPtr
MethodTable: 5ec0c5a0
EEClass: 5e7e9f00
Size: 12(0xc) bytes
File: C:\Program Files\Microsoft Silverlight\4.0.50524.0\mscorlib.dll
Fields:
MT Field Offset Type VT Attr Value Name
5ec0d720 4000353 0 PTR 0 instance 0bb9a86c m_value
5ec0c5a0 4000354 50c System.IntPtr 1 shared static Zero
>> Domain:Value 0b670f20:NotInit 0b675a40:NotInit <<
4. The address of the target object is 0bb9a86c. Now we can use !dumpobj command to print it:
0:025> !dumpobj 0bb9a86c
Name: HelloSl.FooBar
MethodTable: 07625428
EEClass: 07621cd8
Size: 12(0xc) bytes
File: HelloSl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Fields:
None
Random thoughts, ideas and questions on .NET development