.net

What is the "cost" of reflection?

I am currently in a programming mentality that Reflection is my best friend. I use it a lot for dynamic loading of content that allows "loose implementation" rather than strict interfaces, as well as a lot of custom attributes. The question I have is, what is the "real" cost to using reflection? Is it worth the effort for frequently ...

What's the best way to write a short[] array to a file in C#?

I have an array of shorts (short[]) that I need to write out to a file. What's the quickest way to do this? ...

Change order of XML using XDocument

I want to change the order of XML using XDocument <root> <one>1</one> <two>2</two> </root> I want to change the order so that 2 appears before 1. Is this capability baked in or do I have to do it myself. For example, remove then AddBeforeSelf()? Thanks ...

Why are there multiple different hashing algorithm providers in System.Security.Cryptopgraphy?

As documented by the MSDN here, there are several providers for many of the different hashing algorithms (e.g. MD5, SHA, RIPE). For each of the algorithms, any available implementation seems to fall into 1 of 3 categories: [Algo]Cng [Algo]CryptoServiceProvider [Algo]Managed Why are there multiple implementations of any of these hashi...

Cleanest syntax to delete a record in linqtosql

What is the best way to delete a database record using LINQ when I have the primary key? ...

How to get a webserice to serialize/deserialize the same type in .net

I want to use typed parameters in the web methods. But when visual studio 2005 creates the web reference on for the client it automatically creates it's own types. I am using a .net web service and a .net client. For example: < WebMethod > _ Public Function Foo() as ServerNamespace.Bar ... End Function at the client the method beco...

Loosely coupled events in WPF without using Prism

I'm working on a WPF application and is using the Model-View-ViewModel pattern. The application consists of two modules at the moment: Left Panel to browse a tree and select a node Main Panel to show the content of the selected tree node. I want to keep these two modules seperated, but when I select a node in the Left Panel I need t...

datetime subtract .net

i want to get datetime for 2days before. i.e) how to subtract 2 days from datetime.now ...

Transactions in .net

What are the best practices to do transactions in C# .Net 2.0. What are the classes that should be used? What are the pitfalls to look out for etc. All that commit and rollback stuff. I'm just starting a project where I might need to do some transactions while inserting data into the DB. Any responses or links for even basic stuff about ...

How to embed Ruby in an XNA engine?

I'm wondering if it's possible to embed Ruby as a scripting language in Microsoft XNA, and what's the best way to do that. I'm looking for something like Xnua, except for Ruby. I've stumbled upon Ruby.NET and IronRuby and both seem to be in very early stages, so I'm not sure how usable they are. Furthermore, I'm not sure if they'd work...

Thread local storage with __declspec(thread) fails in C++/CLI

I'm working on a project where we mix .NET code and native C++ code via a C++/CLI layer. In this solution I want to use Thread Local Storage via the __declspec(thread) declaration: __declspec(thread) int lastId = 0; However, at the first access of the variable, I get a NullReferenceException. To be more precise, the declaration is don...

Dragging & dropping items from one list to another in a ASP.NET page?

I would like to move items from one list to another on a page, and I'm pretty flexible about what type of a list it is. What's the best way to do that? ASP.NET Ajax? jQuery? Anything else? ...

Can I create a unit test for a method which marshalls a value from an IntPtr?

I am using a native library which returns an IntPtr to a memory location, which contains the value of an attribute. I know what the type of the attribute is and I have a method for marshalling a value (taking the IntPtr and the type of the attribute) from the memory pointed at by the pointer. This method either calls Marshal.ReadInt32,...

Code Coverage on Visual Studio Team System 2008 Developer Edition (on an NUnit application)

Is this possible? I am looking forward to a tutorial which explains the steps to achieve this. ...

Receive parameter from request body in WCF/ADO.NET Data Service

I'm tryint to post to a ADO.NET Data Service but the parameters seems to get lost along the way. I got something like: [WebInvoke(Method="POST")] public int MyMethod(int foo, string bar) {...} and I make an ajax-call using prototype.js as: var args = {foo: 4, bar: "'test'"}; new Ajax.Requst(baseurl + 'MyMethod', method: 'POST', ...

Can I load a 32 bit DLL into a 64 bit process on Windows?

I recently upgraded a c# windows service to run as a 64 bit .net process. Normally, this would be trivial, but the system makes use of a 32-bit DLL written in C++. It is not an option to convert this DLL to 64 bit, so I wrapped the DLL in a separate 32 bit .net process and exposed a .net interface via remoting. This is quite a reliable ...

Where is the documentation for My feature in VB.Net?

No I'm not being a wise guy ... For those fortunate enough to not know the My class: It's something that was added in VB 2005 (and doesn't exist in C#) and is best described as a 'speeddial for the .net framework'. Supposed to make life easier for newbies who won't read which framework classes they should be using Dim contents As Stri...

How to force uninstallation of windows service

I installed a windows service using installUtil.exe. After updating the code I used installUtil.exe again to install the service w/o uninstalling the original version first. When I now try to uninstall the service, installUtil.exe completes the uninstall successfully, but the service still appears. If I try to change its properties,...

calling managed code from unmanaged code

Hi, I want to call my .NET code from unmanaged C++. My process entrypoint is .NET based, so I don't have to worry about hosting the CLR. I know it can be done using COM wrappers for .NET objects, but I would like to access individual static methods of managed classes, so COM isn't my shortest/easiest route. Thanks! ...

Exposing an enum from a library class

In C#, I am using a library that defines an enum. I would like to allow consumers of my code (in a different assembly) to pass in an enum value as a parameter to one of my functions without having to reference the underlying library themselves. Is there a way for me to expose the library's enumeration to my consumers? ...