Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations

Browse by Tags

All Tags » CodeSnippets (RSS)
Tales from the Unmanaged Side – System.String –> char* (pt. 2)
A while ago, I posted an entry about marshalling a managed System.String into an unmanaged C string, specifically a plain char*. The solution I suggested, back in 2007, involved calling Marshal::StringToHGlobalAuto method to allocate memory and copy the...

Posted Tuesday, January 13, 2009 5:04 PM by Avner Kashtan | 3 comment(s)

Filed under: , ,

Static Constructor throws the same exception again and again
Here’s a little gotcha I ran into today – if you have code in a class’s static constructor that throws an exception, we will get a TypeInitializationException with the original exception as the InnerException – so far, nothing new. However, if we keep...

Posted Tuesday, December 16, 2008 12:17 PM by Avner Kashtan | 5 comment(s)

Filed under: , ,

Upgrading all projects to .NET 3.5
A simple macro to change the Target Framework for a project from .NET 2.0 to .NET 3.5, hacked together in a few minutes. This will fail for C++/CLI projects, and possibly VB.NET projects (haven't checked). Works fine for regular C# projects, as well as...

Posted Sunday, May 25, 2008 11:56 AM by Avner Kashtan | 2 comment(s)

System.Diagnostics.EventLogEntry and the non-equal Equals.
Just a quick heads-up in case you're stumped with this problem, or just passing by: The System.Diagnostics.EventLogEntry class implements the Equals method to check if two entries are identical, even if they're not the same instance. However, contrary...

Posted Sunday, November 25, 2007 8:12 PM by Avner Kashtan | 3 comment(s)

Filed under: , ,

Displaying live log file contents
I'm writing some benchmarking code, which involves a Console application calling a COM+ hosted process and measuring performance. I want to constantly display results on my active console, but since some of my code is running out-of-process, I can't really...

Posted Wednesday, November 21, 2007 4:12 PM by Avner Kashtan | 4 comment(s)

Filed under: , ,

Dynamically creating a Sharepoint Web-Service proxy instance
In my current code, I find myself accessing many Sharepoint web services. In one run of code I can access 5-6 different web services on dozens of different sites, not necessarily even on the same server. Given that I find myself writing a lot of boilerplate...

Posted Monday, September 03, 2007 7:55 PM by Avner Kashtan | 7 comment(s)

Allowing timeout on long-running operations - possible bug
A while ago, I wrote about a simple pattern to allow us to put a timeout limitation on a long running operations. Simply put, it allows us to replace this: public MyObject GetData() { try { MyObject data = BigComponent.LongRunningOperation(); return data;...

Posted Monday, August 27, 2007 10:18 AM by Avner Kashtan | 5 comment(s)

Filed under: , ,

Retrieving all properties for a Sharepoint list
When we call the GetListItems or GetListItemChanges methods in Sharepoint's Lists Web Service, we pass an XmlNode parameter specifying which fields we want to return, in this format: <ViewFields> <FieldRef Name="ows_ID"/> </ViewFields>...

Posted Sunday, June 03, 2007 10:33 PM by Avner Kashtan | 5 comment(s)

Filed under: , , ,

Granting User Rights in C#
As a follow-up to my previous post about changing a Windows Service's user account - there was one think I forgot. In order for a user to run a service, that user must be granted the "Run as Service" right by the operating system. Usually it's not a problem...

Posted Thursday, May 10, 2007 12:36 PM by Avner Kashtan | 1 comment(s)

Filed under: , , ,

Setting Windows Service Account - C# and WMI
I've been busting my brains for over two hours trying to accomplish a relatively simple task - changing the username and password of a currently running Windows Service. Should be trivial enough, but the managed ServiceController class doesn't give me...

Posted Tuesday, May 08, 2007 10:54 AM by Avner Kashtan | 11 comment(s)

Filed under: , , ,

More Posts Next page »