Menu Close

Category: ASP.NET

NRW2013 – Conference day

20131011_161645After living 5 months in Germany, given opportunity and encouragement I finally got from under the rock and went to IT event – NRW2013 conference. Language barrier is still big obstacle, but, as it turned out, listening to well illustrated talks on subjects that touch more or less known domain is not very hard. NRW2013 conference consists of 2 days – one workshop day and one conference day. I attended only conference day.

Custom Tool Error when updating service reference in VS 2010[Solved]

Day as usual, I was assigned some task to do in project, that I am working on. To meet the requirement I had to update service reference to one of WCF web-services included in solution. This was nothing new, service was in this solution almost from the start of the project, even before I got to work on it, being one of it’s central parts. I was really surprised, when operation, that I’ve completed many times before failed with error:

Error    27    Custom tool error: Failed to generate code for the service reference ‘<<serviceName>>’. Please check other error and warning messages for details.

After looking through the warnings I’ve found that three of them seemed to be the causes of this error. They looked something like this:

Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
<some more info, some XPaths>

and alike for “port” and “portType”. I’ve looked at Reference.cs – there was no code inside, only some generated, commented out header.

That’s a bummer! After googling I’ve found that most popular solutions were:

  • remove reference, restart VS, add it from scratch
  • try restarting machine
  • check “Reuse types from referenced assemblies”
  • if you have installed VS2012 uninstall it reinstall VS2010

First and second one did not work. Third one was no good solution. Well, it made service reference to update, but in project referencing it I had all types doubled, so ambiguous types references all over the place. Fourth solution did not help.

Different approach to reading data from SqlDataReader [source code included]

When reading data from SqlDataReader you have to know your select statement’s columns order to read and map data from database to your model. Often it looks somehow like this:

using (SqlDataReader reader = command.ExecuteReader())
	if (reader.Read())
		return new AnimalModel
			AnimalId = reader.GetInt32(0),//or better with enum like that: AnimalId = reader.GetInt32((int)AnimalSelect.AnimalId)
			BirthDate = reader.GetDateTime(1),
			Name = reader.GetString(2)
	else return null;

It’s a good practice to create enum representing select’s columns and using it instead of int indexes.
But wouldn’t it be better if you could just do it like that:

using (SqlDataReader reader = command.ExecuteReader())
	if (reader.Read())
		return reader.ReadObject();
	else return null;