.net

Down with Defensive Coding (against exceptions)?

I've noticed a lot of code lately (mine included) that, e.g. makes a DAL call, and then checks to see if the returned DataSet is not null, then checks to see if it has tables, then it returns Tables[0]. If there is no DataSet, I would rather see hell raised ... and a few exceptions, than have a user wandering where all there invoices ar...

Forcing a tab to the next control in an extended .net control

Say I'm extending a TextBox called CustomTextBox in .net. In certain situations I would like to force a tab to the next TabIndex on the form. Is there a way to do this beyond getting all the controls contained in CustomTextBox's parent, sorting them by their TabIndex, and then focusing the next ordinal one? ...

To CurrentThread.Abort or not to CurrentThread.Abort...

I've seen a number of examples that have a thread procedure that looks like this. private void ThreadProc() { while (serviceStarted) { // do some work Thread.Sleep(new TimeSpan(0, 0, 5)); } Thread.CurrentThread.Abort(); } Is the Abort() really necessary at the end? ...

Killing an interop Application process

I have the following in a program (written in VB.NET): Imports Microsoft.Office.Interop.Excel Public Class Form1 Dim eApp As New Excel.Application Dim w As Excel.Workbook w = eApp.Workbooks.Open( "path.xls", ReadOnly:=True) .. Processing Code .. //Attempts at killing the excel application w.Close() eApp.Work...

Is it ok to write my own extension methods in the system namespace?

I've been using extension methods quite a bit recently and have found a lot of uses for them. The only problem I have is remembering where they are and what namespace to use in order to get the extension methods. However, I recently had a thought of writing the extension methods in the System namespace, System.Collections namespace or s...

How do you rename the child XML elements used in an XML Serialized List<string>?

Hello, I'm serializing to XML my class where one of properties has type List<string>. public class MyClass { ... public List<string> Properties { get; set; } ... } XML created by serializing this class looks like this: <MyClass> ... <Properties> <string>somethinghere</string> <string>somethinghere<...

Accessing a list of avaliable Wifi APs, on Windows Mobile.

I need to query for a list of available Wireless Access points. I only need their SSIDs. The App is currently .Net CF 2.0, but it's not a problem going with 3.5 if we have to. ...

Why is this property Getter virtual?

Having a strange issue with some C# code - the Getter method for a property is showing up as virtual when not explicitly marked. The problem exhibits with the DbKey property on this class (code in full): public class ProcessingContextKey : BusinessEntityKey, IProcessingContextKey { public ProcessingContextKey() { // Not...

Modifying PDF document properties

How can I modify the PDF document properties programmatically using .NET code? I have purchased a number of eBooks in PDF format and unfortunately the publishers have not set the Title, Author and Subject properties. You can see this on a document by accessing the file Properties dialog and selecting the PDF tab. This is a real pain whe...

Signing a mixed mode C++ assembly

Can you sign a C++ CLI application that is partially managed and partially unmanaged? ...

How can I inform the implementor of my Interface that the "path" parameter represents a folder?

I am about to define an interface in my application that plug-in writers can implement to provide user-defined "export" capabilities. It'll look something like this: public interface IFooExporter { void ExportFoo(Foo foo, string path); } However, I need to let the plug-in writers know (explicitly, not just in documentation) that "...

Configuration: When does IsReadOnly take effect?

This is a simple question, but one I'm not finding much information for in the docs. When dealing with custom configuraiton sections, collections, elements, etc, when does the IsReadOnly setting actually mean read only? With IsReadOnly returning True, I can still do things like MyBase.Item("property") = value; Are these classes only "r...

.NET ClickOnce and Vista start-up

We have some software we use internally which is released via ClickOnce from VS 2008. The app needs to run on everyones computer all the time so the obvious solution is to have it in the Start Up folder of their start menu. This works fine on XP machines. But, as was inevitable, people are moving to Vista. Now we're hitting a problem wh...

WriteOnly Property or Method??

Is there a particular scenario where a WriteOnly property makes more sense then a method? The method approach feels much more natural to me. What is the right approach? Public WriteOnly Property MyProperty As String Set(ByVal value as String) m_myField = value End Set End Property public string MyProperty { set{ m_myFiel...

Is there a type of object, to which I can cast both Buttons AND Menutem objects in order to access their Tag properties?

I want to cast both MenuItem objects and Button control objects to an object type of whose "Tag" property I can reference. Is there such an object type? E.g. void itemClick(object sender, EventArgs e) { Control c = (Control)sender; MethodInvoker method = new MethodInvoker(c.Tag.ToString(), "Execute"); method.Invoke(); } ...

Static Class Vs. Class with private constructor and all static properties and methods?

When I create utility classes I typically create a class that has a private constructor and exposes all of it's methods and properties as static. What's the best approach for this? What's the difference between the way I do or creating a static class? ...

Querying Complex Data Structure in Memory

Hi all, First time posting to a questions site, but I sort of have a complex problem i've been looking at for a few days. Background At work we're implementing a new billing system. However, we want to take the unprecedented move of actually auditing the new billing system against the old one which is significantly more robust on an on...

System.BadImageFormatException "invalid format" when trying to install service with installutil.exe

I am trying to install a Windows service using InstallUtil.exe and am getting the error message System.BadImageFormatException - invalid format What gives? ...

Where to begin and how to participate in .NET community?

I'm new to .NET and I would like to participate with .NET community to grow my skills (selfish, I know), contribute something (not so selfish) and I thought its just nice to be part of a community. I can start a blog but considering I'm a beginner I can't possibly post anything worthwhile. How about opensource projects? Are there ways t...

Http Request - Bypass DNS [.Net]

Is it possible (and if yes, how) to bypass DNS when doing a HTTP request ? I want to hit directly a front-end with an HTTP request, without getting through NLB but with the correct host header. As I have the IP of my server, I just need to bypass the DNS. I tried to use WebRequest, replacing the URL with the IP and setting the Host he...