Monday, February 26, 2007

This is what happens when you forget to deploy your Telerik RadControls folder

This article applies specifically to applications developed using Telerik Rad Controls

I was having a stupidus momentus (tm) yesterday, I forgot to deploy the RadControls and I kept getting this error:

Object reference not set to an instance of an object.
at Telerik.WebControls.RadWindowManager.BuildTemplates()
at Telerik.WebControls.RadWindowManager.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at Telerik.WebControls.RadAjaxManager.AJAX_Page_Render(HtmlTextWriter output, Control container)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Telerik could do better with their exception handling, but anyway... I just needed another pair of eyes to see the issue

Tuesday, February 20, 2007

My name

Miguel de Icaza (one of the guys behind Mono) tells us how "english speakers" mispronounce his name (Mi-goo-elle), I don't think that's bad at all, in my case I get

ee-ber
Aber
A-bear
Heber

and let's not even try my last name

I have to explain that my name is like in "forever"... but most of the time I don't even bother now, you just get used to it

Thursday, February 15, 2007

time for a refactorer job title

from Jeff Atwood post code smaller
It's up to us to resist the natural tendency of any project to snowball into a giant rolling Katamari ball of code. Code smaller!
for the last 4-6 months I have eliminated about 3-5 times more code than I have written (maybe more than that!?), specially using generics, as everything else in life (hopefully) you get better at it the more you do it.

but I have seen this problem over and over again in many different teams, and the sad part is that the problem is not specific to new developers, experienced developers keep doing it the same way

It seems is time for a new job title whose primary responsibility is to refactor code, and the members of the team should learn from him and start to follow

of course the actual job title would have to be much cooler than "Refactorer"

Wednesday, February 14, 2007

Before you ask...

nowadays everyone thinks they know how to use google (pretty much in the same way people assume they know how to use Windows... sigh)

For a lot (most?) of things it works fine by entering a few words (although it helps to know which words you shouldn't put on your search), but sometimes is not so easy to find the stuff, that's when you need to use your google search skills, at minimum you need to know these ones:

- intitle:
- link:
- site:
- intext:
- inanchor:
- inurl:
- filetype:
- define:
- using quotes
- using wildcards
- using OR, AND
- using -
- using ranges

If you don't know how to use all the "commands" on this list, you are missing a lot.
There are many other interesting tools built right into google.com, like:

- calculator
- conversions
- UPS, Fed Ex, USPS tracking information
- VIN information
- movies
- etc, etc, etc

check this page for a very complete list of things you can do with google, included all of the items in my list

Tuesday, February 13, 2007

good bye username and password

Whenever you use user names and passwords in your applications, consider using System.Net.NetworkCredential to pass the information around functions, it encapsulates those fields, and allows you to extend in the future to maybe use a domain as well.

In my case we're using it in a plugin architecture to authenticate against any system, using this class encapsulates those fields and allows the plugin to authenticate against most standard systems as it is not tied specifically to username and password

Saturday, February 10, 2007

magic variables to help in exception debugging

This article applies to C#, J#, and Visual Basic.
I read about these variables a long time ago in some blog, but I could not find anything about those hidden little things, mainly the problem was that they are not called magic or hidden, they are documented and are called Pseudovariables;

Pseudovariables are terms used to display certain information in a variable window or the QuickWatch dialog box. You can enter a pseudovariable the same way you would enter a normal variable. Pseudovariables are not variables, however, and do not correspond to variable names in your program.

Anyway, I don't think many people know about them, here they are:
  • $exception: Displays information on the last exception. If no exception has occurred, evaluating $exception displays an error message.
    In Visual C# only, when the Exception Assistant is disabled, $exception is automatically added to the Locals window when an exception occurs.
  • $user: Displays a structure with account information for the account running the application. For security reasons, the password information is not displayed
when you are debugging an exception you might have some code like this:

try {
//some code
} catch (Exception e) {
//don't really need e here, just to get the exception information on the Watch window
}

you could write this code as:
try {
//some code
catch { } //put the breakpoint on this line, inspect $exception (Debug, Watch, Watch 1, type $exception there)

and get the same information.

The $user pseudovariable is pretty self explanatory.

in native code you have a few more pseudovariables available, check the link if you are interested.

those little things...

Friday, February 09, 2007

DOS attack on google using google tools?

just noticed this post on the Google Operating System blog that shows how to backup your blogspot hosted blog, it basically allows you to run a query like this:

http://ebersys.blogspot.com/search?max-results=N

that retrieves N posts for such blog

but what if the bad guys just decide to use that and query a bunch of blogspot pages all at the same time? that would be a lot of data coming from the google servers, I just tried this one

http://googlesystem.blogspot.com/search?max-results=2000

and it took quite a while to download

the fix would be easy, they can put restrictions on who can run the query, for example just require that the blogspot user is authenticated and you can only run the query on your blog

unless google doesn't care and they can handle that just fine, we'll see

As a general rule, unless you are part of google, don't allow your users to run queries that return all the rows in your tables... is not a good thing

Thursday, February 08, 2007

protected, internal, protected internal... are you sure you know them?

the code for this article applies to C#

We all take access modifiers for granted, but can you tell me what protected internal does?

I bet more than half .NET developers will get that wrong, let's review:
  1. private:
    1. This is the least permissive access level.
    2. Accessible only within the body of the class or the struct in which they are declared.
    3. Nested types in the same body can also access those private members
  2. public:
    1. This is the most permissive access level.
    2. There are no restrictions on accessing public members, they are visible anywhere the class is visible
  3. protected:
    1. Access is limited to the containing class or types derived from the containing class.
    2. which means you cannot create an instance of a class and have access to protected members.
  4. internal:
    1. Access is limited to the current assembly.
  5. protected internal:
    1. Access is limited to the current assembly or types derived from the containing class.
that last one is kinda tricky, it kinda "makes sense" that it allows access only in the current assembly and the current or derived classes, but the "or" there is what makes a difference, if you mark a property protected internal, it can actually be accessed outside the assembly. basically protected overrides internal and so I'm not even sure when it makes sense to use such modifier.

If you don't believe me go check it out your self:
Assembly1:
public class Test {
protected internal string prop1;
}

Assembly2://after adding a reference to Assembly 1
public class Test2: Test {
public string prop2;
public Test2() {
prop2 = prop1; //came from the other assembly's class protected internal member
}
}

if this is news for you, you might think, that's stupid, how do you get a property to be visible only the the current assembly, current class and derived classes?

quite simple, you mark your class as internal, so your class can only be accessed from the current assembly, and you mark your property as protected, thus giving access to the derived classes only in the current assembly:

internal class Test {
protected string prop1; //accessible only in this assembly in this class and derived classes
}

Sunday, February 04, 2007

VS2005, VS2007 (Orcas), XNA, LINQ, WPF in Vista

how is that for a title... =o)

Justin and I were playing today with these technologies, it wasn't so much fun as we expected, in short all those things don't work together in Vista, if you want more details read on
  • VS2005 doesn't work on Vista, it crashes randomly and very often
  • VS2007 works fine on Vista
  • XNA development is not supported on VS2007 or Vista, only in VS2005 Express
  • the latest WPF is not supported in VS2007, only in VS2005
  • LINQ works fine on VS2007
so if you're thinking about playing with any of those technologies in Vista, reconsider using Windows XP