RemotingException Using IPC With .NET

In a project I’m using IPC (Inter Process Communication) for sharing objects of a Windows service with a client application.

This always worked correctly when the client application started the first time and used the objects of the Windows service. But starting the client application (without restarting the service) some minutes later again, resulted in a RemotingException with this strange error message:

Failed to write to an IPC Port: The pipe is being closed.

It took me quite long to figure out what the problem was:
as it is important for my service to really have only one instance of the remote object for the whole lifetime of the service, I used RemotingServices.Marshal to register a previously instantiated object. But I did not know that objects registered with this method are only valid for a very short time period (one minute) by default.

To fix that you need to override the MarshalByRefObject.InitializeLifetimeService method within your remote server object like this:

public override Object InitializeLifetimeService()
	ILease lease = (ILease)base.InitializeLifetimeService();
	if (lease.CurrentState == LeaseState.Initial)
		lease.InitialLeaseTime = TimeSpan.FromDays(365);
		lease.SponsorshipTimeout = TimeSpan.FromDays(365);
		lease.RenewOnCallTime = TimeSpan.FromDays(365);
	return lease;

And here the same for VB .NET developers:

Public Overrides Function InitializeLifetimeService() As Object
	Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
	If lease.CurrentState = LeaseState.Initial Then
		lease.InitialLeaseTime = TimeSpan.FromDays(365)
		lease.SponsorshipTimeout = TimeSpan.FromDays(365)
		lease.RenewOnCallTime = TimeSpan.FromDays(365)
	End If
	Return lease
End Function

OK, 365 days are probably a little bit exaggerated, but this way you can be really sure your remote objects won’t expire very fast. ;-)

Did you come across this problem yourself already, too?

Flags Widget as Easy to Use WordPress Plug-In

Some minutes ago I’ve released my second WordPress plug-in: A simple plug-in that displays flag icons that link to other language versions of your blog.

This plug-in combines my widget for displaying language selection flags in menu and footer with many additional options and settings in one clean WordPress plug-in.

The installation and configuration is very easy. Just have a look und let me know your thoughts!

Using Visual Studio Form Designer With Forms Extending Abstract Classes

For a recent project I wanted to create an abstract form base class. This way some global functionality can be inherited by all of my forms and interface methods can be defined.

But the result was this error message as soon as I tried to open one of my derived from classes in the Visual Studio form designer:

The designer must create an instance of type <type name>, but it can't because the type is declared as abstract.

Hereupon I’ve searched for a solution in the web and it seems that I was not the only one that had the idea to derive some form classes from an abstract base class. To solve the problem I’ve created a dummy implementation of my abstract base class and derived the form classes from this dummy implementation. This way the form classes can be displayed in the Visual Studio form designer again.

In C# the classes look like this then:

public abstract partial class BaseForm : Form
  // Methods of your abstract class...

public class BaseFormImpl : BaseForm
  // The dummy implementation of the abstract BaseForm class.

public partial class RealForm : BaseFormImpl
public partial class RealForm : BaseForm
  // One of the forms extending the base form.

And for VB .NET developers it looks like this:

Public MustInherit Partial Class BaseForm
  Inherits Form
  ' Methods of the abstract base class...
End Class

Public Class BaseFormImpl
  Inherits BaseForm
  ' The dummy implementation of the abstract BaseForm class.
End Class

Public Partial Class RealForm
  Inherits BaseFormImpl
  Inherits BaseForm
  ' One of the forms extending the base form.
End Class

Probably you have noticed the compiler directives: obviously that’s not necessary that the forms work correctly inside the form designer again. But I don’t like to have unnecessary code inside the released product (and the dummy implementation of the abstract BaseForm class is really useless). Therefore I used these conditional compiler directives to make sure that this dummy class is only used in debug mode.

Did you come across this issue yourself already, too?

IDF 2011: Panel Discussion About Developing Apps for Multiple Devices

Today I was invited to join the panel discussion “Apps Across the Compute Continuum: Developing Apps for Multiple Devices” at the Intel Developer Forum (IDF) in San Francisco.

IDF 2011 Panel Discussion

It was a pleasure for me to discuss together with other Intel Black Belts like Chris Skaggs (Soma Games), Lee Bamber and Rick Vanner (The Game Creators) and Suresh Kumar (Blue Innovations) as well as Bob Duffy (Intel AppUp Community Manager and moderator of this panel discussion) the pros and cons, but also the challenges of developing apps for multiple devices and platforms.

Have you been to the IDF 2011, too?

Most Important Social Widgets as Easy to Use WordPress Plug-In

Some minutes ago I’ve released my first WordPress plug-in: it displays the most important social widgets of Facebook, Twitter and Google+ below your posts.

Now the question is:
Why yet another social widgets plug-in as there are already a lot of them?

The answer is that I’ve searched for a simple and easy to user plug-in and all plug-ins I’ve found were way to complicated: I did not want to have countless of social networks supported with hundreds of options – just a simple plug-in covering the most important social widgets without needing to configure anything!

And that’s my new plug-in:
Install it, activate it and the social widgets are displayed below your posts immediately – without doing any configuration.

What social widgets plug-in do you use?

Create New Posts With Publishing Date in WordPress Using XML-RPC and PHP

To be able to add new posts to a WordPress blog I wanted to use XML-RPC interface with PHP.

First of all you need to enable the checkbox “Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols.” in the menu “Settings”/”Writing”.

Now I searched on the web for a ready-to-use solution as I was probably not the first one who wanted to accomplish that. And as expected there were also many PHP scripts doing exactly that, but with one problem:
I wanted to set also the publishing date manually with the PHP request and most scripts I’ve found did not even try to do that at all.

Few scripts in fact did try to set the publishing date, but the result was an error message similar to:
Fatal error: Call to a member function getIso() on a non-object in /var/www/wp-includes/class-wp-xmlrpc-server.php on line 2373

After reading some documents regarding this strange ISO 8601 date format that is needed there, I found a solution myself:

 * Performs a XML-RPC to a WordPress blog and adds a new post.
 * @param string $title Title of the new post.
 * @param string $body Body text of the new post.
 * @param string $rpcurl RPC-URL of the blog (normally xmlrpc.php in the root directory).
 * @param string $username User name used to add the new post.
 * @param string $password Password used to add the new post.
 * @param string $categories Comma separated list of categories (make sure they already exist in your blog).
 * @param string $keywords Comma separated list of keywords/tags (in contrast to the categories they don't need to exist already).
 * @param string $pubdate Publishing date in ISO 8601 (with date('c') in PHP; current time is used if empty).
 * @param string $draftonly True to save as draft only, False to publish directly (default).
 * @return string The result of the XML-RPC.
function wpPostXMLRPC($title, $body, $rpcurl, $username, $password, $categories, $keywords = '', $pubdate = '', $draftonly = false) {
	$content = array(
		'title' => $title,
		'description' => $body,
		'mt_allow_comments' => 1,
		'mt_allow_pings' => 1,
		'post_type' => 'post',
		'date_created_gmt' => '%pubdate%', // Just as place holder here.
		'mt_keywords' => $keywords,
		'categories' => array($categories)
	$params = array(0, $username, $password, $content, !$draftonly);

	$request = xmlrpc_encode_request('metaWeblog.newPost', $params);
	// Now we need to set the real publishing date:
	$request = str_replace('<string>%pubdate%</string>',
			       '<dateTime.iso8601>' . $pubdate . '</dateTime.iso8601>',

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
	curl_setopt($ch, CURLOPT_URL, $rpcurl);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 1);
	$results = curl_exec($ch);
	return $results;

As you can see I inserted the data structure needed for the correct ISO 8601 date format myself directly into the XML request. This is probably not the most elegant way, but it works perfectly. ;-)

Did you come across the same issue already yourself?

The Solution for Multilingual Blogs in WordPress

After I’ve tested several options for multilingual blogs in WordPress (see this post), Dennis Ploetner called my attention to his not just yet very famous, but excellent plug-in in a comment.

The Multisite Language Switcher allows you to simply use a multisite WordPress configuration with one WordPress administration for every blog language and still have a relation between the language versions of your posts, categories and tags.

That’s really great, because this way you don’t have the problem with all these translation plug-ins that you always have to make sure that every additional plug-in you use (like a special SEO plug-in) also supports the used translation plug-in. Otherwise you cannot add let’s say a translation for your page title or description which is important for SEO reasons.

But not with this plug-in: as it depends only on the default and official functionality of a WordPress multisite configuration, you can use whatever plug-in that supports the WordPress multisite functionality.

You may say it is unfunctional that you need to login to another WordPress admin area to change a translation. But with the current version of this plug-in each translation is linked in the admin area directly (just click on the language flag). This way it is very easy to switch between different translations in the edit mode.

You can see this plug-in in action here, of course:
it can add a link below every post to its translations. Additionally the flags displayed on the blog pages link directly to the translations of the current page, too.

As a summary I can only recommend to try this plug-in if you are searching for a solution to build a multilingual blog in WordPress.

Do you know other good solutions for multilingual blogs in WordPress?

FAQ on Code Signing Certificates and Digital Signature

In the following I will answer some frequently asked questions about code signing certificates and digital signature.

How long is a code signing certificate valid?

Normally one year, but you may be able to order code signing certificates that lasts up to 5 years.

Is it necessary to resign apps or files after the code signing certificate has expired?

No, because together with your digital signature a timestamp is included and therefore the signature of a signed app or file never expires – even if your certificate itself expired already.

Do I have to resubmit an app to Intel AppUp after the code signing certificate expired?

As the signature of the app itself does not expire (see above), this is not necessary. Only if you want to release an update, you have to sign the app again and resubmit it afterwards.

How many apps or files can I sign with one code signing certificate?

There is no limit: you can sign any number of apps or files with just one code signing certificate.

What documents are needed to obtain a code signing certificate?

Depending on whether you request the code signing certificate as an individual person or a company, you may need an articles of incorporation or a business license. You should also be prepared that you may be asked for a copy of your phone bill. Then somebody will call you at the phone number stated on this bill to verify it is valid.

How to obtain a certificate and how to sign files?

Do you have more questions?
Just leave a comment and I’ll try my best to answer them. ;-)

German Translation for MailPress Plug-In

As I am using the MailPress plug-in to support blog and comment subscriptions, I needed a German translation for it. Unfortunately the only available German translation for this plug-in was completely outdated. Therefore I decided to create one on my own.

Download the German translation file:

Just unzip the translation files into the folder /mailpress/mp-content/languages/.

If you find mistakes, please post below!

Widget for Displaying Language Selection Flags in Menu and Footer

After I decided to use the WordPress Multisite feature for my multilingual blog (see this post), I wanted to display language selection flags inside the menu and in the footer.

It turned out that especially the integration of images on the right side of the (by default black) menu area was not very easy in the “Twenty Eleven” theme. Therefore I decided to just create a simple widget that displays the flags in a DIV which is placed above all other content and this way can easily be positioned with relative coordinates directly from within the admin widget interface.

Therefore you can define these settings in the admin area:

Flags Widget (Admin Interface)

  • Flag position offset (left): the relative offset of the X coordinate of the DIV.
  • Flag position offset (top): the relative offset of the Y coordinate of the DIV.
  • Flag icon URL (en): the flag icon URL for the English flag (first uploaded, of course).
  • Flag icon URL (de): the flag icon URL for the German flag (first uploaded, of course).

Obviously this can be easily extended with more or other languages if needed.

And here is the widget source code:

 * Flags_Widget Class
class Flags_Widget extends WP_Widget {
	/** constructor */
	function Flags_Widget() {
		parent::WP_Widget(false, $name = 'Flags_Widget');

	/** @see WP_Widget::widget */
	function widget($args, $instance) {
			<div style="position: relative;">
				<div style="left: <?php echo $instance['flags_position_left']; ?>px; top: <?php echo $instance['flags_position_top']; ?>px; position: absolute; z-index: 10000 !important;">
					<?php echo '<a href="/en/"><img src="' . $instance['flag_en'] . '" width="20" height="16" title="English" alt="English" />'; ?></a>  
					<?php echo '<a href="/de/"><img src="' . $instance['flag_de'] . '" width="20" height="16" title="Deutsch" alt="Deutsch" /></a>'; ?>

	/** @see WP_Widget::update */
	function update($new_instance, $old_instance) {
		$instance = $old_instance;
		$instance['flags_position_left'] = strip_tags($new_instance['flags_position_left']);
		if (!is_numeric($instance['flags_position_left'])) $instance['flags_position_left'] = '0';
		$instance['flags_position_top'] = strip_tags($new_instance['flags_position_top']);
		if (!is_numeric($instance['flags_position_top'])) $instance['flags_position_top'] = '0';
		$instance['flag_en'] = strip_tags($new_instance['flag_en']);
		$instance['flag_de'] = strip_tags($new_instance['flag_de']);
		return $instance;

	/** @see WP_Widget::form */
	function form($instance) {
		$flags_position_left = esc_attr($instance['flags_position_left']);
		if ($flags_position_left == '') $flags_position_left = '0';
		$flags_position_top = esc_attr($instance['flags_position_top']);
		if ($flags_position_top == '') $flags_position_top = '0';
		$flag_en = esc_attr($instance['flag_en']);
		$flag_de = esc_attr($instance['flag_de']);
				<label for="<?php echo $this->get_field_id('flags_position_left'); ?>"><?php _e('Flag position offset (left):'); ?></label>
				<input class="widefat" id="<?php echo $this->get_field_id('flags_position_left'); ?>"
					name="<?php echo $this->get_field_name('flags_position_left'); ?>" type="text" value="<?php echo $flags_position_left; ?>" />
				<label for="<?php echo $this->get_field_id('flags_position_top'); ?>"><?php _e('Flag position offset (top):'); ?></label>
				<input class="widefat" id="<?php echo $this->get_field_id('flags_position_top'); ?>"
					name="<?php echo $this->get_field_name('flags_position_top'); ?>" type="text" value="<?php echo $flags_position_top; ?>" />
				<label for="<?php echo $this->get_field_id('flag_en'); ?>"><?php _e('Flag icon URL (en):'); ?></label>
				<input class="widefat" id="<?php echo $this->get_field_id('flag_en'); ?>"
					name="<?php echo $this->get_field_name('flag_en'); ?>" type="text" value="<?php echo $flag_en; ?>" />
				<label for="<?php echo $this->get_field_id('flag_de'); ?>"><?php _e('Flag icon URL (de):'); ?></label>
				<input class="widefat" id="<?php echo $this->get_field_id('flag_de'); ?>"
					name="<?php echo $this->get_field_name('flag_de'); ?>" type="text" value="<?php echo $flag_de; ?>" />
} // class Flags_Widget
add_action('widgets_init', create_function('', 'return register_widget("Flags_Widget");'));

I wanted to keep it simple and therefore all together in one file. Otherwise you should at least put the CSS styles inside an external style sheet file, of course.