Archive for the ‘tip’ Category

When should one learn a new technology?

June 9th, 2010

The short answer is Now!

Not now as in ooh-shiny! but as in I-have-to-learn-this-anyday-anyway.

Take this example: Linq.
Linq is a sterling technology for writing code that is easy to read and have fewer bugs.  It takes an hour or two to grasp but is payed back when the first bug is avoided.  Here is the cherry on top: you will have to learn Linq one day.  So why keeping on building your technical debt?
Is it smart?  No.

categories: tip | no comments »

When should one update?

June 9th, 2010

The short answer is Now!

Not now as in update-right-before-delivery but now-since-we-will-update-anyway-someday.

Take this example: You have a web site running on dotnet2.  You know that dotnet has updated not one but two steps since then.  You also know of goodies like Linq.  If you google for dotnet2->4 problems you will not see many.

So what is keeping you?
Every day you don’t update you will build on your technical debt.  Since you didn’t upgrade 2->3.5 two years ago 1)the debt is greater  and 2)the update is bigger.
Smart move?  No.

categories: tip | no comments »

Use App_Offline.htm to take down your site and give the user a nice message in a simple way

May 5th, 2010

If you want to take down an aspnet2 site but still give the user a web page with some other info than 404; just drop  a file named App_Offline.html with contents of choice in the direcotry and IIS will gracefully take down the sessions and instead show your message.  Remove the file and you are up again.

Honor those who should.

categories: tip | no comments »

The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

April 24th, 2010

If you get the error above in your web browser it might be due to Visual studio 2010 not updating the web.config file.

—-

Creating an Entity framework 2 multi tier (n-tier/ntier) aspnet mvc 2 solution in Visual studio 2010 wasn’t the next-next-next or just-follow-an-example I first thought.

The first try rendered a “The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.” message in the browser.  There were mainly two answers through google:
1) create a Mydatalayer.dll.config and insert the connection string there
2) update the web.config and insert the connection string there

I tried them both to no avail. I knew my connection string was correct because I could use it through a test dll.

Finally I found out that the web.config file in the web project does not get copied to the output.  It fooled me since I saw that there were 3 web config files (ordinary+debug+release) in the site.

Now I don’t dare to set the web.config in VS2010 to Copy-if-newer since the web.config already in the site has almost 80 rows already and I don’t want to overwrite it.

Updating the web.config in the site will save me for now.  I will figure out how to do it the right way later.

categories: tip | 6 comments »

System.Data.Objects.DataClasses.EntityObject with Entity Framework 4

April 16th, 2010

If you for instance create a multi layered application and get the compilation error

The type ‘System.Data.Objects.DataClasses.EntityObject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.

when you compile the business layer just add a reference to System.Data.Entity.

categories: tip | 5 comments »

Visual Studio 2010 installation

April 12th, 2010

If you get

—————————
Microsoft Visual Studio 2010 Ultimate Setup
—————————
Some components must be installed in c:\Program Files\Microsoft Visual Studio 10.0\ directory. Check that you have write permissions and enough space in that directory.
—————————
OK
—————————

when you try to install Visual studio 2010; don’t despair.
There is a big chance you try to install from a mounted virtual disc.

The solution is to copy the files in the mounted disk to real files and run it from there. One could possibly also assign the mounted disk a letter but I haven’t tried this.

I have learned that there is also some problem when installing from a network share. The symptom is something about a .cab file with a faulty digital signature.

categories: tip | no comments »

Coderush and camelCase and select

March 16th, 2010

I am a long time fan of DPack. Some time ago Coderush stepped up to a must-have.

The other day I noticed that Coderush did camel case selection. It is like this:
Open the Vsnet editor with your favourite project and go to a camelCased or PascalCased word. Select it with ctrl-shift-right/left. This is old news.
Now instead use alt-shift-right/left; only a part of the word is highlighted. Perfect when copy-pasting variables like CustomerName and SerialNumber.

Coderush comes both in gratis and payed versions.

categories: tip | no comments »

Aspnet MVC 2 starter project compilation error

March 15th, 2010

When starting your first Aspnet MVC2 project you might immediately run into compilation errors like these:

Error 1 The type or namespace name ‘Controllers’ does not exist in the namespace ‘MvcApplication1’ (are you missing an assembly reference?) C:\myprojectpath\MvcApplication1.Tests\Controllers\HomeControllerTest.cs 8 23 MvcApplication1.TestsError 3 The type or namespace name ‘Models’ does not exist in the namespace ‘MvcApplication1’ (are you missing an assembly reference?) C:\myprojectpath\MvcApplication1.Tests\Controllers\AccountControllerTest.cs 10 23 MvcApplication1.Tests

Error 4 The type or namespace name ‘AccountController’ could not be found (are you missing a using directive or an assembly reference?) C:\myprojectpath\MvcApplication1.Tests\Controllers\AccountControllerTest.cs 317 24 MvcApplication1.Tests

The origin of the problem is that the test project doesn’t reference the web project. Just add the reference and you’re good to go.

I haven’t found the solution on google yet so I write this here to someones possible future aid.

>Checking events in VBNet

March 4th, 2010

>Due to some reason unknown to man the team behind VBNet decided that the developer should not be able to see if someone listened to your event or not. It is good in most cases but very bad in another.

In Csharp raising an event goes something like this:
var ev = MyEvent;
if( null != ev ){ ev( this, args ); }

Just look through the snippets (look in the context menu in the editor) and you will find the correct way to raise an event in Csharp.

VBNet on the other hand hides the if statement and the temporary variable from the developer. It is enough to write
RaiseEvent Me, args
and the event will be raise if there is someone listening – no need to check for null.

But what if you want to check if someone is listening. In my case I needed to know if the custom control was properly wired into the scaffolding of the application; the user control sometimes whished for more information and I had to know if someone was listening.
In Csharp this would have been easy with a check for null. But VBNet…

The solution is hidden. Just check the variable “MyEventEvent“. This means that your MyClick event has a hidden variable MyClickEvent that you can check for like this:
If MyClickEvent IsNot Nothing Then

I don’t like to use hidden and unoffical solutions but this is the only way I know of.

Honor those who should.

>Share a file in Visual Studio

January 28th, 2010

>

I didn’t think it was possible but it has been for years; to share a file between projects in a solution.

Add a file the normal way but instead of pressing Open, use the little dropdown arrow next to.  Then you have the possibility to “link” instead of “add”.

This makes it possible to have one and only one file for many places.  It can be a source code file or a readme or anything really.
I have yet to try it with TFS and SVN to make sure it doesn’t mess upp the version management.

Honor those who should.

On a side note: Sourcesafe has linking ability within itself.  I miss it in TFS.  Though: It is easy to lose the master file and keep copies wich makes strange icons.  It also doesn’t play well with the VB6 editor when a file will be checked out and another not, but they should be, but the VB6 ide doesn’t understand it and you have to do an explicit checkout and… never mind.  It was a long time ago.

categories: tip | no comments »