.net

My team member added a reference to a third party DLL and did a check-in...now I can't build.

My team member made a reference to a DLL on his local drive (e.g., C:\mystuff\thirdparty.dll) and checked in the project with the reference. I refreshed my local copy of the project and now I have a broken reference: <The system cannot find the reference specified>. I have the thirdparty.dll on my local machine, but it is not in the sa...

Selecting a good dictionary key

I have an object that I want to use to look up other objects. I will be using a Dictionary<TKey, TValue>(). The key object has two strings that uniquely identify it, say KeyObj.Str1 and KeyObj.Str2. What do you recommend that I use as the key for the dictionary? 1: The concatenation of the strings. Dictionary<String, TValue>(); Key...

Driving DTR with System.IO.Ports.SerialPort in .NET

I have a sensor that uses RS232 over USB to receive commands from a PC and send data to the PC. The sensor needs to be reset (using the DTR line) before a command can be sent to it. I tried to use the built-in .net serial port, but it does not seem to drive the DTR line as expected. I am beginning to wonder if the DTREnable property ac...

Writing to the command line in a windowed app

I'm trying to get my WinForm based C# to cooperate with the commandline too, but I'm having difficulty getting it to play nice. For example, I have this code: [STAThread] static void Main(string[] args) { foreach (string s in args) { System.Windows.Forms.MessageBox.Show(s); Console.WriteLine("Stri...

ASP.NET Click Event Handle - How to pass an argument in VB.NET ?

I'm using the accordion Ajax control. For each Accordion pane I have text and a Button dynamically created. When the user fires the click event I want to know what button in which pane was fired. So I want to handle the button's click event in a way that I can send the ID (probably by event args) to the event handler in order for the han...

Avoiding the ABA problem in .NET code

Please note that I already know of and understand the ABA problem. This question is about the behavior of the .NET memory model with regard to ABA. In his discussion of the Lock-Free LIFO Stack (CLR Inside Out column from May 2007 MSDN Magazine), Joe Duffy says: "We incur an object allocation for each Push, saving us from having to wor...

The filename, directory name, or volume label syntax is incorrect, c#

i've written a console application deploy.exe which runs a batch script. Process p1 = new Process(); p1.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "installer.bat"; p1.StartInfo.WindowStyle = ProcessWindowStyle.Normal; p1.Start(); p1.WaitForExit(); p1.Close(); the installer.bat conatins the following command. \shared1...

Using Delegates AND Declaring Events

I'm developing a class library to be used for other developers and will be allowing them to either declare an instance of my class using WithEvents (or similar in other languages) as well as allow them to use Delegates defined in the class. Am I just being redundant here by doing it like this? Public Delegate Sub TimerElapsedDelegate(B...

Some advanced questions on the using statement

I know there are a number of threads on here about how to use the using statement and calling the Dispose() method. I have read the majority of these threads. If I call Dispose(), does it call Close()? If I want to use an object (say SqlDataReader), but then use it again in another code block, should I not call Dispose()? Which also me...

Databound DataGridView Empty Despite Full DataSource

I have a base form class that contains a method that returns a DataTable: protected DataTable GetTableData(string sql, OracleConnection connection) { DataTable table = null; OracleDataAdapter adapter = null; try { table = new DataTable(); adapter = new OracleDataAdapter(sql, connection); table.Locale = System.Global...

Binding controls to class properties - is this technically possible?

I have yet to find a "nice" way to do two way databinding in .Net. The one thing I don't like for example in the present asp.net two way databinding is doing the binding in the aspx page is no compile time checking, ie: <asp:TextBox ID="TitleTextBox" runat="server" Text='<%# Bind("Title_oops_spelled_wrong") %>'>...

How can I delete IIS objects from c#?

I need to delete a Virtual Directory and Application pool from .NET as part of my uninstall method. I found the following code on the web somewhere: private static void DeleteTree(string metabasePath) { // metabasePath is of the form "IIS://<servername>/<path>" // for example "IIS://localhost/W3SVC/1/Root/MyVDir"...

Signalling Initialization Failure from Service.OnStart

We have a case where during Service startup (OnStart), a worker thread is started. The worker thread connects to a SQL database. If the database is unavailable, the worker thread can signal the main thread of the failure. The question is; How to signal the Service Control Manager that startup has failed. ...

Why is my Uninstall method not called from the msi?

Hi, I am writing an installer for my web app and I struggle with the uninstaller part. Despite the fact that I created a custom action on Uninstall in my Application Setup Project, the InstallerClass is set to true, the method: public override void Uninstall(IDictionary savedState) { //MessageBox.Show("Attach debugger!", "V...

Silverlight: Invalid Attribute Type for TargetType="{x:Type TextBlock}"

Just playing around with Silverlight a bit and trying to set a style to apply to all TextBlocks. The following XAML: <Style TargetType="{x:Type TextBlock}"> <Setter Property="Margin" Value="10, 10, 10, 10" /> </Style> Gives me the error Invalid attribute value {x:Type TextBlock} for property TargetType. I copied and pasted this bi...

Good reasons to pass paths as strings instead of using DirectoryInfo/FileInfo

In my new code I am not using strings to pass directory paths or file names. Instead I am using DirectoryInfo and FileInfo as they seem to encapsulate a lot of information. I have seen a lot of code that uses strings to pass directory information then they "split" and "mid" and "instr" in long incomprehensible statements until they get...

Refresh Crystal Reports without "Parameter Values" dialog

I am running Crystal Reports Basic for Visual Studio 2008. I would like to dynamically refresh my report based on a parameter. For instance, I'll have a customer contract and I want to switch between customers based on a VB.NET winform button click. I was expecting the code below to work, but I keep getting the "Enter Parameter Values...

Serialize .NET Array to XML as base 64?

I'm writing a custom .NET serializer in C# and want to read and write Array objects to XML using XmlReader and XmlWriter. I would like to base64-encode the Array. The arrays may be 1-, 2- or 3-dimensional and the elements are bool or numeric types. I'm completely stumped. XmlReader and XmlWriter have methods for reading/writing Byte[] ...

Resharper and the C# Catch Clause

I'm new to Resharper and I'm trying to understand why it seems to suggest: catch (Exception) { } for catch { } and catch { } for catch (Exception) { } I'm baffled. ...

optimize updates to DataTable bound to DataGridView

I have a Form in my application that displays some data. When I first show the Form, I load some data into a DataTable then bind the DataTable to a DataGridView. I also start an asynchronous method that executes some slower database queries. When these slow queries complete, I need to update a few hundred rows in the DataTable, filling i...