.net

Build setup project with NAnt

I've already got a NAnt build script that builds/runs tests/zips web project together, etc. but I'm working on a basic desktop application. How would I go about build the setup project using NAnt so I can include it with the build report on TeamCity. Edit: The setup is the basic Setup Project supplied with Visual Studio. It's for inte...

Using CreateItemFromTemplate to process an olEmbeddeditem Outlook attachment

I am using C# to process a message in my Outlook inbox that contains attachments. One of the attachments is of type olEmbeddeditem. I need to be able to process the contents of that attachment. From what I can tell I need to save the attachment to disk and use CreateItemFromTemplate which would return an object. The issue I have is...

Is there a way to override the empty constructor in a class generated by LINQtoSQL?

If I have a table in my database called 'Users', there will be a class generated by LINQtoSQL called 'User' with an already declared empty constructor. What is the best practice if I want to override this constructor and add my own logic to it? ...

Why is it impossible to override a getter-only property and add a setter?

Why do you think (or, why is it good that) Microsoft chose not to allow: public abstract class BaseClass { public abstract int Bar { get;} } public class ConcreteClass : BaseClass { public override int Bar { get { return 0; } set {} } } ...

Extension Methods not working for an interface

Inspired by the MVC storefront the latest project I'm working on is using extension methods on IQueryable to filter results. I have this interface; IPrimaryKey { int ID { get; } } and I have this extension method public static IPrimaryKey GetByID(this IQueryable<IPrimaryKey> source, int id) { return source(obj => obj.ID == id)...

How to catch ALL exceptions/crashes in a .NET app

I have a .NET console app app that is crashing and displaying a message to the user. All of my code is in a try{} catch(Exception e){} block, but still errors are occasionally displayed. In a Win32 app, you can capture all possible exceptions/crashes by installing various exception handlers: _set_se_translator SetUnhandledExceptionFil...

Best way to read commandline parameters in console application

Below are two ways of reading in the commandline parameters. The first is the way that I'm accustom to seeing using the parameter in the main. The second I stumbled on when reviewing code. I noticed that the second assigns the first item in the array to the path and application but the first skips this. Is it just preference or is ...

In WPF, what is the equivelent of Suspend/ResumeLayout() and BackgroundWorker() from Windows Forms.

If I am in a function in the code behind, and I want to implement displaying a "Loading..." in the status bar the following makes sense, but as we no from WinForms is a NoNo: StatusBarMessageText.Text = "Loading Configuration Settings..."; LoadSettingsGridData(); StatusBarMessageText.Text = "Done"; What we all now from Win...

In C# .NET 2.0, what's an easy way to do a foreach in reverse?

Lets say I have a Dictionary object: Dictionary myDictionary<int, SomeObject> = new Dictionary<string, SomeObject>(); Now I want to iterate through the dictionary in reverse order. I can't use a simple for loop because I don't know the keys of the dictionary. A foreach is easy: foreach (SomeObject object in myDictionary.Values) { ...

Reading PDF documents in .Net

Is there an open source library that helps me reading/parsing PDF documents in .Net/C#? ...

Entity Framework and Application Architecture (loose coupling, etc)

I am considering to apply Entity Framework in a new project because I liked its OR/M-API as well as the storage/conceptual model mapping-capabilities (plus Linq of course and Entity SQL). But how can loose coupling be achieved betwen the UI layer and the business layer if EF entities are used as dataholders in both. If I leave the entit...

Is there a serializable generic Key/Value pair class in .NET?

I'm looking for a key/value pair object that I can include in a web service. I tried using .NET's System.Collections.Generic.KeyValuePair<> class, but it does not properly serialize in a web service. In a web service, the Key and Value properties are not serialized, making this class useless, unless someone knows a way to fix this. Is ...

How can I get the unique values of an array in .net?

Say I've got this array: MyArray(0)="aaa" MyArray(1)="bbb" MyArray(2)="aaa" Is there a .net function which can give me the unique values? I would like something like this as an output of the function: OutputArray(0)="aaa" OutputArray(1)="bbb" ...

How much time do you spend in Reflector? (.NET)

As a consultant I get to toy around with many different products and APIs as the customer demands we use X and Y. I think it is great fun and I learn a lot from it. What will make a great developer over time is, in my opinion, the will to understand and learn new things. Therefore, I will always try to understand what happens "behind th...

Are there any Fuzzy Search or String Similarity Functions libraries written for C#?

There are similar question, but not regarding C# libraries I can use in my source code. Thank you all for your help. I've already saw lucene, but I need something more easy to search for similar strings and without the overhead of the indexing part. The answer I marked has got two very easy algorithms, and one uses LINQ too, so it's p...

Is there a Functional Programming library for C# .NET?

For example, in Java there is Functional Java and Higher-Order Java. Both essentially give a small API for manipulating higher-order, curried functions, and perhaps a few new data types (tuples, immutable lists). ...

Is .NET a write once, run anywhere (WORA) platform like Java claims to be?

I remember Sun's slogan so vividly... "Write Once, Run Anywhere". The idea being that since programs are compiled into standard byte codes, any device with a Java Virtual Machine could run it. Over the years, Java seems to have made it onto many platforms/devices. Is this the intention or was it ever the intention of .NET. If so, what ...

How do I prevent static variable sharing in the .NET runtime?

I'm working on a game (C#) that uses a Robocode-like programming model: participants inherit a base Class and add strategic behaviors. The game then loads instances of participants' Classes and the competition begins. Unfortunately, participants can "cheat" by sharing static variables between instances of their competitor Class. How do ...

Preferred logging infrastructure for .Net

What is your preferred logging infrastructure for .Net - NLog, log4net, other? Please, specify why you would use one vs. another (pros and cons). Edit: I find it really difficult to "accept" an answer, as there is no enough data to compare. I.e. favoring one of the possibilities, w/o specifying features, that others lack, or are better ...

Please help me with my .NET abstract classes.

I'm designing a web site navigation hierarchy. It's a tree of nodes. Most nodes are pages. Some nodes are links (think shortcuts in Windows). Most pages hold HTML content. Some execute code. I'd like to represent these as this collection of classes and abstract (MustInherit) classes This is the database table where I'm going to ...