mono can be a bitch – the following assembly could not be loaded: System.Windows.Forms

What the hell does this mean?

** (MyProgram.exe:2938): WARNING **: The following assembly referenced from /home/dj/Development/MyProgram/MyProgram.exe could not be loaded:
Assembly:   System.Windows.Forms    (assemblyref_index=1)
Version:    2.0.0.0
Public Key: b77a5c561934e089
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/home/dj/Development/MyProgram/).

** (MyProgram.exe:2938): WARNING **: Could not load file or assembly ‘System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies.

** (MyProgram.exe:2938): WARNING **: Missing method EnableVisualStyles in assembly /home/dj/Development/MyProgram/MyProgram.exe, type System.Windows.Forms.Application

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ or one of its dependencies.
File name: ‘System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′

it means (or at least it did for me) that you need to:

sudo apt-get install libmono-winforms2.0-cil

Automatic Reference Counting Issue

I just started following the Core Data Tutorial for iOS and wanted to apply Core Data to an existing project.  I got up to a point where I was init-ing my NSManagedObjectModel.  I started to get some errors that didn’t make sense right away.

Automatic Reference Counting Issue
Receiver ‘NSManagedObjectModel’ for class message is a forward declaration

I discovered that this error really means I’m missing an #import of some CoreData stuff.  To fix the problem I simply add the following line to /Supporting Files/projectName-Prefix.pch.

#import <CoreData/CoreData.h>

Resetting GNOME panels

Using Ubuntu I end up screwing up my taskbar a lot.  This is an easy way to get them back to their default state:

gconftool –recursive-unset /apps/panel

rm -rf ~/.gconf/apps/panel

pkill gnome-panel

That should get them back to their default state!

ActiveRecord HQL LIKE query with parameters

I get asked almost every day never how to do a LIKE in an HQL query with parameters.

I want to change this

string hql = "FROM Table t WHERE t.Name=:nameParameter";

into this

string hql = "FROM Table t WHERE t.Name LIKE %:nameParameter%";

It isn’t that simple, this will throw a QueryException.

With a little help from Stefan Pettersson’s blog I found my solution, add the percent signs inside the parameter.

string hql = "FROM Table t WHERE t.Name LIKE %:nameParameter%";
query.SetParameter("nameParameter", "%" + nameParameter + "%");

Xubuntu windows cover the taskbar and don’t have resize buttons

I installed Xubuntu 9.10 on an old desktop system this morning.  That bring my house to 3 Xubuntu and 1 Windows Vista.  But there was a problem with my windows when I opened any program.  The didn’t have the normal minimize, maximize, close buttons in the upper right corner.  Also the windows covered the taskbar in the upper left corner of the desktop.  I was not able to alt+tab between windows when I did manage to get 2 programs open at the same time.  See screen shot below:

This was quite frustrating but it didn’t take long to find an easy fix.

Thanks to some forums that I can’t find now again I was able to open a termial window and type:

xfwm4 –replace &

This immediately fixed the problem.  I hope it works for you as well.

UPDATE:

Now once in a while my desktop loads up and I don’t get any task bar.  My windows are at least resizable and movable but it is still annoying.  After a quick search I found that I can do alt+F2 and then type xfce4-panel which bring back my taskbar.

It only happens sometimes and I’m not sure how to permanently fix it.  Let me know if you have any ideas.

How to find what program has a port open on Windows XP

If you ever need to figure out what program might have a specific port open for some reason here is an easy 2 steps that will get you what you need.

From a command prompt type:

netstat -noa | findstr :1042

this should give you some output that looks similar to this:

TCP 0.0.0.0:1042 0.0.0.0:0 LISTENING 1952

From that line you take the last number (1952) which represents the process id. Then type:

tasklist /fi "PID eq 1952"

Here is the result as you would see this whole process.

netstat example

I’ve found myself having to look up how to do that twice. Now that I’ve written it here I’ll remember it.

Installing a Canon Pixma MX700 over network on Linux (Xubuntu 9.10)

This has been a huge pain in the ass.  Over the past couple of days I’ve successfully installed my Canon Pixma MX700 over the network on both Ubuntu and Xubuntu 9.10.   I eventually found this post on the Ubuntu forums that led me to the information I needed.  It was still spread out on a few different sites so I decided I’d make a guide here that details everything I did to get it working.

I don’t understand what exactly was going on in every step, but it did work.  I was working on Xubuntu 9.10 that had just been installed and updated.

apt-get install libcups2-dev

Download the following files:

apt-get install alien

You may have to do apt-get install -f

Seems the files downloaded in step number 2 need some special conversion if you are using version 9.10 or later, issue the following commands

  • alien -r cnijfilter-common_2.80-1_i386.deb
  • alien cnijfilter-common-2.80-2.i386.rpm

Insall the new deb file created in the previous step: dpkg -i cnijfilter-common_2.80-3_i386.deb

Do the same for the other file downloaded:

  • alien -r cnijfilter-mp520series-2.80-i.i386.deb
  • alien cnijfilter-mp520series-2.80-2.i386.rpm –scripts

Insall the new file again: dpkg -i cnijfilter-mp520series_2.80-3_i386.deb

mkdir /usr/share/cups/model – download http://ubuntuforums.org/attachment.php?attachmentid=54929&d=1199213424 & mv canonmx700.ppd.txt /usr/share/cups/model/canonmx700.ppd

Download the cups-bjnp.  This allows CUPS to print over the network.  http://sourceforge.net/projects/cups-bjnp/files/ I got version 0.5.4 which does say it works with CUPS version 1.2 and 1.3.  I have CUPS version 1.4.1 which did end up working.

Unpack the downloaded file tar xvzf cups-bjnp-0.5.4.tar.gz and then change into the new directory cd cups-bjnp-0.5.4.

Now set up this package: ./configure and then make install

type ./bjnp to test the installation so far.  You should get back a long string back that starts out like “network bjnp://192.168.11.12:8611 “Canon MX700 series…..”

this might be a good time to restart CUPS: /etc/init.d/cups restart

Now you have to open a web browser and go to http://localhost:631/.  Click on the administration tab and the “Add Printer” button.  Hopefully you will eventually see your printer show up on a list.  Select it and follow the next couple of step with the default settings.  When you are asked to select from a list or browse for a file – browse and select the file copied ea rlier /usr/share/cups/model/canonmx70.ppd.

When I look at the Show Completed Jobs on the CUPS admin website I see “Failed to read side-channel request!” in the state column.  This made me think my print jobs were not done, but they were actually going through and printing.

Hopefully your printer is now ready to print over the network from your Ubuntu or Xubuntu 9.10 computer.

WPF Binding to nullable types

WPF binding can be confusing.  There are still times where I encounter a problem that I have no idea how to solve.  Thanks to Google I usually find my solution.

Today I was working with binding on a text field to a nullable double property.  Consider the following situation: My textbox and property both start out with a valid double value.  Then I delete everything from the textbox.  At the point my setter should fire for the property it sees an empty string and doesn’t assign any value because my property is a double.  So how do you actually get that to recognize that is should change the property to null?

Thanks to Maxim Alexeyev’s Discoverting .NET blog I was able to find the easy solution.

Add TargetNullValue to your binding.  Now my binding looks like this.

Text=”{Binding SomeNullableDoubleProperty, TargetNullValue={x:Static System:String.Empty}}”

This makes sure that anytime my textbox sees a String.Empty it knows to treat that as a null. When I remove any value from the textbox a null value is set to my nullable double type and everyone is happy!