Archive for the ‘.NET’ Category

Unobtrusive client validation in ASP.NET MVC 3

Monday, November 29th, 2010

Recently I walked through the pains of setting up flexible client-side validation on ASP.NET MVC 3 project. After all the hassle, the solution is actually pretty easy and elegant. All the information is available on the internet already but the One And Only blog post that explains it everything seems to be missing. So here it is.


Blocked file madness in Windows 7

Monday, October 25th, 2010

Some time ago Rytmis wrote about Windows Vista’s annoying security feature. I had similar-looking problem with blocked files, but the solution was a bit different. Specifically, I was trying to use .NET Reflector Pro’s Visual Studio add-in. I enabled Visual Studio integration from Reflector (Tools->Integration Options -> Visual Studio 2010) and all was good. However, when restarting Visual Studio I got an error message that .NET Reflector add-in cannot be loaded (of course, without any meaningful error message). It was easy to guess that this has something to do with files downloaded from the internet. (more…)

.NET Framework will be renamed

Thursday, April 1st, 2010

Many of Microsoft’s technologies have been renamed to be consistent with each other and to form uniform product lines. Most of the base technologies are called foundation technologies. A rush at that arena was at the launch of .NET Framework 3.0. Then was released the new user interface technology Windows Presentation Foundation (WPF), formerly known as Avalon; the new model for distributed programming Windows Communication Foundation (WCF), formerly known an Indigo and the underlying technology for all new workflow applications, Workflow Foundation (which was then called WWF, but the official acronym is now WF).

Now, at the release of Sharepoint 2010, the lite version formerly known as Windows Sharepoint Services, will be renamed to Sharepoint Foundation.

Finally, the naming of these fundamental technologies will achieve it’s closure: The programming framework and paradigm that we originally called Lightning, was released under the name .NET Framework. Now, at the release of version 4.0 the framework will also be renamed to conform to this naming convention and as expected, the new name will be Windows Technology Foundation. To celebrate this remarkable milestone, Microsoft has acquired the well known site and will continue to bring daily news about all WTF technologies.

Visual Studio 2010 editions

Tuesday, October 20th, 2009

Now that Visual Studio 2010 beta 2 is out, some new information about the packaging of the product is also revealed. Gone is the old jumble of nearly dozen different flavors. Now everything comes in three different products: Visual Studio Professional, Visual Studio Premium and Visual Studio Ultimate. (more…)

Linq to SQL is not dead meat

Tuesday, July 21st, 2009

My old WP got hacked, and this post got deleted. Basically, all I said can be founf from Jouni’s post.

Mysterious experiences in the world of reflection using TypeDescriptor

Monday, July 13th, 2009

In the process of implementing server-side validation for an ASP.NET MVC project using great xVal library, I found an interesting..err.. dare I say bug in the .NET framework. I used xVal and dataannotations on Linq2SQL objects, pretty much following the guidance here. Of course, I wanted the error messages localized and luckily, the ValidationAttributes have properties called ErrorMessageResourceName and ErrorMessageResourceType so it shouldn’t be a problem.

Following eXtreme Programming principles, I wanted first to have it work doing the simplest possible solution. Just add a plain required attribute and test. Voilá, it works! Great, so let’s add the localization in place. I added the attribute properties and suddenly the validation didn’t work anymore. Why is that? After close examination with debugger and Reflector I found that:

  • According to reflector the attributes are there and their properties are correctly set
  • According to VS debuggerTypeDescriptor.GetProperties(myModelObject).Cast().ToList()[0].Attributes doesn’t contain the RequiredAttribute!

That’s interesting. No exceptions were raised, no error messages were given. The attribute was plain missing and thus validation didn’t work.

OK, let’s try it another way. Inspect the object using ordinary reflection methods using the following code:

foreach (var pi in instance.GetType().GetProperties())
 Console.WriteLine(“Propertyname: {0}\r\n “, pi.Name);
 foreach (var a in pi.GetCustomAttributes(true))
  Console.WriteLine(” “ + a.GetType().ToString());

This code raised runtime exception “Unhandled Exception: System.Reflection.CustomAttributeFormatException: ‘ErrorMessageResourceName’ property specified was not found.” Whaaat!? I just checked that it is there. Reading the stacktrace more closely, I found ystem.InvalidOperationException: The resource type ‘MetadataTest.ModelValidationResource’ does not have a publicly visible static property named ‘XXX’.

Ok, so the resource should be public? Indeed, resources are generated as internal by default. Luckily the resource editor allows me to set the access modifier as public. Let’s retest. Now the new code goes through correctly. How about the code using TypeDescriptor? Now it works too! So, a few things to remember when using localized model validation

  • Remember to set resources as public
  • Do not trust TypeDescriptor as it silently sucks all exceptions and errors

I guess I need to ask Microsoft whether this is by design. Basically this kind of errors should never be ignored.