Sharing .NET generic code under the hood

If you come from a C++ programming background, you are most likely already familiar with C++’s template code bloat problem. Each template instantiation gets its own copy of the code (of course, compiler/linker can optimize by throwing away unused methods). The reason being that C++ template are more like C macro on steriods. I know…

0

C# value type boxing under the hood

I recently had some really interesting discussion with a .NET typesystem expert in the team, and during the conversation he had pointed out an interesting aspect of .NET value type boxing when using constraints. Intrigued by that discussion, I decided to take a further look. See the full article here in my new blog yizhang82.me  

0

Moving my blog to GitHub pages - http://yizhang82.me

I haven’t posted in a good while – it’s because I’ve been busy working on .NET native! Now that things has settled down for a bit, I’ve decided to resume writing posts. After spending some time thinking, I’ve decided that I prefer writing my blog posts in plain text/markdown and working on Git repos, rather…

0

Getting rid of TypeLoadException in your WinRT app

I’ve seen enough people asking about this so I thought I should talk about this in my blog. They see strange first-chance TypeLoadException happening in their application but it doesn’t seem never cause any problem (app doesn’t crash) and everything still seem to work ‘fine’. This seem to happen mostly if you have a C++…

0

Async talks on Channel 9

Even though I work on .NET interop and WinRT these days, async/await is still the one topic that gets me confused from time to time. It’s a great concept logically but difficult to grasp once you start thinking about how the actual code flow goes (and all hell breaks loose once you start debugging the…

0

Avoiding C++ types in your P/invokes

It’s easier to explain this in an example. Let’s say you have a export function in your native DLL: void WINAPI MyFunction(_com_ptr_t<IMyInterface> ptr) { // … do something with ptr ptr->Func(); } And the DllImport would be something like this: [DllImport("mydll.dll")] void MyFunction(IMyInterface ptr); Everything seems to be perfectly valid, except that there is a…

0

WARNING: VS 2012 might break your broken P/Invoke

I’m seeing many people reporting that they are seeing strange P/invoke issues when they moved their code to VS 2012. Typically, they have P/invokes like this: [DllImport("Win32Project2.dll", PreserveSig = true, CharSet = CharSet.Unicode)] static extern int MyPInvoke(out string ret); If you attach a native debugger (or enable native debugging), with the right symbols (public symbol…

2

Marshal.GetHRForException does more than just Get-HR-For-Exception

Let’s first start by looking at a small code snippet: if (Marshal.GetHRForException(myException) == E_SOME_COM_ERROR) DoSomething(); This looks perfectly fine, right? Not really. It turns out this API is actually poorly named, and it actually does more than just retrieving the HR from the exception object. Using this API incorrectly could give you some weird problems,…

0

Effective WinDbg breakpoints using hit counts

I learned this debugging trick from a colleague a few days ago when we are debugging a bug together and I can’t wait to share it. Conceptually it is really a simple idea but it is very helpful. Let’s say you are debugging a crash. You know the bug is probably in function A but…

0

If your Windows Phone 7 doesn’t sync with Zune Software, try a different USB port

I recently got Samsung Focus but it doesn’t get recognized by the Zune Software – it says “No device connected”, even though my phone did ring a sound when it connects to my computer and zune software did pop up. Spend half hour searching for solutions and I run into this article: http://www.microsoft.com/windowsphone/en-us/howto/wp7/basics/the-zune-software-doesnt-recognize-my-phone.aspx One of…

1