Welcome Guest, you are in: Login

##CSharp @ Freenode - Wiki



Search the wiki



Modified on 2012/04/10 15:25 by AndyJ Categorized as Uncategorized



Q: I am too cheap to buy a book, how else can I learn?

A: See our other pages about online resources. Also, Charles Petzold wrote a free book DotNetZero which covers everything you need to know before reading this Code+Markup=Applications book.


Q: How can I parse this HTML/XHTML/XML using regular expressions?

A: You can't.

Q: How can I validate this email address?

A: It's not easy if you're going to insist that validation means 'its format is correct'. See the follow-up post where it's conceded that there's only one way to 'validate': Try sending mail.


Q: Using a DllImport calling the method multiple times in a loop is very slow, is there anything I can do to improve the performance?

A: Yes!


Visual Studio

Q: Why when I add a Web Reference to Web Service in another project in my solution does the code generator still generate entirely new custom data types?


Problem Description

Sometimes you have data classes (custom types) that hold your data and have little handy helper methods on and stuff (e.g. ToString overridden etc). Obviously since they hold data you’re probably going to send them over the Web Service rather than take each bit of data out and send it through separately.

i.e. ‘[WebMethod] void SendData(MyDataClass myDataClass)’ rather than ‘[WebMethod] void SendData(string dataPart1, string dataPart2, int dataPart3)

The problem arises at the client end, even if you reference the shared Assembly so that the original types are available the client Add Web Reference will still just use the description the Web Service publishes to recreate the types rather than using the existing ones. It’s a good thing that it does this as you don’t want unneeded data in your Web Service but it is annoying, especially when your original data classes have helper methods.


Thankfully MS have provided us with a lot of extensibility in Visual Studio and so we have a way to make the process smarter. You can decorate your data classes with the XmlType attribute, which allows you to assign a namespace. Using this namespace and a custom class we can make the Add Web Reference generator know that it can use pre-existing types rather than making its own.

That process is described in this article:
Customizing generated Web Service proxies in Visual Studio 2005


Q. Why do I get "TF14087: Cannot undelete because not all of the deletion is being undeleted." when merging?

A. Because theres a bug!

Here's the description of the bug. And here's a post saying it's been fixed in the TFS Orcas Release.

Sql Server

Q. How do I remove all data from an entire database and reset all the autoincrement counters?

A. Jet_Blazer very kindly donated this T-SQL script for doing just that:

WARNING: Obviously this code can be very dangerous, make sure you understand what each part does and that its what you want before running it.

exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
exec sp_MSforeachtable 'DELETE ?'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(?), TableHasIdentity) = 1 BEGIN DBCC CHECKIDENT (?,RESEED,0) END'

ScrewTurn Wiki version Some of the icons created by FamFamFam.