Wednesday, June 22, 2011

Error on Adding WCF Service Reference to ASP.Net Project

I am writing a small website using EF 4 Code First. There are some legacy tables which don't have primary key. This (not having PK) would have created complications with EF, but I needed to only read data from those table. So I decided to create a WCF service to pull the data. I defined [ServiceContract], [DataContract], [OperationContract] etc. and everything was going fine till I tried add reference to my web project. In the Add Service Reference dialog VS did find service, but when I clicked on service to fetch metadata I got following error:

There was an error downloading 
'http://localhost:8732/Design_Time_Addresses/LegacyDataService/DataService/mex'.
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved: 
http://localhost:8732/Design_Time_Addresses/LegacyDataService/DataService/mex.

After some head scratching and googling about the error I found out a post on MSDN forum where somebody was putting [DataMember] attribute over an indexer. I checked my [ServiceContract] and [DataContract]s.

My [ServiceContract] read as follows:

[ServiceContract]
public interface IDataService
{
    [OperationContract]
    IList<LegacyUser> GetUsers();
    ......
    ......
}

I tried to comment the IList<LegacyUser> stuff, but the error was still there. It then occurred to me that there was an Address property which returned build user's address by concatenating other fields. After this Address property was commented the error was gone.

Moral of the story is that:
  1. you should not put [DataMember] attribute on Indexers (as mentioned in MSDN post).
  2. you should not put [DataMember] attribute on properties that use other properties with the attribute to calculate return value.

Wednesday, May 25, 2011

MySQL Error 2002

I was reading an article about MySQL replication yesterday. After reading a bit I thought it will be really easy to test it. I setup a remote MySQL server available with a friend and configured it as master. After this I fired up Ubuntu Lucid Lynx VM in VirtualBox and configured it as slave (changed my.cnf file mainly).

Now when I tried to login into MySQL I got following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
After sifting through many posts on internet forums, I occured to me to check error logs (how intelligent, thought this should have been first thing to do). I issued following command:

tail /var/log/mysql/error.log

110525 23:19:20 [ERROR] /usr/sbin/mysqld: unknown variable 'relay-logn-index=test_slave-bin.index'
110525 23:19:20 [ERROR] Aborting

So it was only an extra 'n' that gave me so much headache. After changing 'relay-logn-index' to 'relay-log-index' it worked fine.

Thursday, January 6, 2011

Making Selected Row Visible in UltraWinGrid

I was facing a problem with Infragistics UltraWinGrid object. There were about 15 rows in the grid. Due to size of form only 8 were visible at a time. The first rows was fixed, so it cannot be moved by scrolling.

To edit row a popup form is opened on double clicking the row and a button on the form. On successful saving of editing information in popup form, parent form's grid is refreshed from database.

Upon refreshing if the very first row (just below the fixed row) was selected or popup was opened by clicking on button when selected row was not visible, it is not scrolled to view.

Unfortunately windows grid does not contains a method like web grid which scrolls selected row to view (ScrollToView).

After some hit and trail I found the following solution:

myGrid.ActiveRowScrollRegion.FirstRow = row;//row is selected row (can get using myGrid.ActiveRow)

Wednesday, October 27, 2010

Ruby On Rails: rspec failing with [no such file to load -- spec_helper]

I have started reading www.railstutorial.org. It is wonderful tutorial for learning Ruby on Rails (ror). I am at chapter 3 currently and tried to setup the unit testing.
After creating project and generating controllers, I installed growl for windows and then autotest, autotest-growl gems. But when I issued the following command:

rspec .\spec\controllers\pages_controller_spec.rb
I got following error:

:29:in `require': no such file to load -- spec_helper (LoadError)
 from :29:in `require'
 from F:/Code/Learning/ruby/todo/spec/controllers/pages_controller_spec.rb:1:in `'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
 from D:/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Going through much pain of reinstalling quite a few gems and banging my head, I went back to read the tutorial page again from beginning and make list of what I have already done as given in page. I found out that I had missed to execute following command:

rails generate rspec:install
It did the folowing:
create .rspec
  exist  
 create  spec/spec_helper.rb
 create  autotest
 create  autotest/discover.rb

Now I had got spec_helper.rb in my spec folder and was able to execute the tests (happily ever after ^_* ).

Also remember to install win32console-color gem to get colorfull info with autotest.
Happy Coding!

Tuesday, February 2, 2010

A way to resolve bugs

I just found a nice blog post by Chris Missal titled "How I Approach a Defect" via a tweet by Elijah Manor.
Chris outlines the systematic approach he takes when solving programming bugs (defects, as he calls them). He underlines the fundamental notion that you should actually fix the problem not just get the right answer for a particular case.
Like Five Ws (5Ws) Chris Missal's defect solving framework tries to ascertain that proper solution has been applied to remove defect by answering following questions:

Does This Solve the Problem? 

Is This Flexible, Maintainable, Clear and Simple?

Does This Leave the Code Better Than I Found It?

Is It Covered with Tests to be Future-Proof?

Is There Any Code that was Commented Out or Stale?

Do Any Named Variables or Classes Exist that Aren't Clear?

Are All Changes Relevant to the Fix?

Please read his post for details of what these questions mean.
Happy Coding!

Monday, November 9, 2009

Free .Net Profiler

I got link for free (as in beer) .Net profiler from eqatec.
It works with many languages:

LanguageVersionPlatform
C#
VB.NET
Managed C++
F#
C or C++
Java
.NET 3.5
.NET 3.0
.NET 2.0
.NET CF 3.5
.NET CF 2.0
.NET 1.1
WinXP, Vista
Windows Mobile
Windows CE
XP embedded
PocketPC, PDA
Linux

Tuesday, October 13, 2009

I got Google Wave Invite!!!

Wow, I got invitation for Google Wave.

Googlewave
preview
Thank you for signing up to give us early feedback on Google Wave. We're happy to give you access to Google Wave and are enlisting your help to improve the product.


can't wait to have a look. Will sure my experiences. Keep watching.....!