The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase’

While I was working with the Open Office XML SDK 2.0, after I added the reference to the DocumentFormat.OpenXml assembly and tried to build the application I ran into this error message.

The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

Turns out, all you need to do to fix it is to just add another reference to WindowsBase assembly that is found in the .NET Tab.

Could not execute CVTRES.EXE

Today I started woking on a windows application at home and I was very annoyed by the error I was getting whenever I tried to debug/build the application that said: “Could not execute CVTRES.EXE

Tried lots of things like giving full rights to “everyone”  on the debug folder and some other silly things, untill I found out that there was something in ZoneAlarm that was causing the problem. I had to uninstall and re-install ZoneAlarm. Turning it off was not sufficient. I never understood what was causing the problem at that time and to be honest I’m not too concerned with that either. May be there was some setting that needed a reset or something. But anyway like they say: “All is well that ends well”!

Hope some of you might find this useful someday.

How to use OrderBy() for multiple columns in EntitySpaces?

You can pass multiple columns in like this:-

collection.Query.OrderBy(collection.Query.ProductID.Descending, collection.Query.CategoryID.Ascending)

How to manipulate Session in Http Handlers

There is a common issue that you can’t manipulate session objects in http handlers, the files with ASHX extension 🙂 Well normally you can read the contents in the session via context.Session but you can add/remove/modify that in there. So how do you do this:

The answer is simple: Just implement the IRequiresSessionState interface. It doesnt have any method to implement so you dont have to worry about any details, this just notifies the runtime that Session can be manipulated in this context. So your class declaration would look something like this:-

public class SetLabels : IHttpHandler, IRequiresSessionState

How to get the file name from a full file path?

If you have a full file path like D:\My Documents\myimg.jpg and you want to get just the file name myimg.jpg, you can get it with the help of the Path class in this fashion:-

In C#

string filename = Path.GetFileName(“D:\My Documents\myimg.jpg“);

Dim fileName as String = Path.GetFIleName(“D:\My Documents\myimg.jpg”)

A lost bet — Response.BinaryWrite Spoils the day!

Two days ago I lost a bet. My friend Jubair was generating a bar code image and he said how can I get it to display on the page without saving it as a file and giving its source to the image tag. I said you can’t do it because I thought it would be possible in desktop applications only. So we made a deal that if I lose I will write a blog entry for him. So here it is. Anyways, he did it in a manner similar to this one.

dim omemorystream as new memorystream(),imagetype)

How to generate Random numbers in .NET

Actually these are not exactly ‘true’ random numbers. These are actually pseudo-random numbers, which means that they give you an illusion that they’re being generated randomly.

It’s very simple: There’s a class called System.Random. and the rest is as simple as this:-

Random r = new Random(0);
int num = r.Next(0,999999);

in VB .NET

dim r as Random = new Random(0)
dim num as Int = r.Next(0,999999)