.net

Do I need to compile my solution with VS2010 in order to benefit from .NET 4.0 new Code Access Security Policy?

Hello, I currently develop an application in C# with framework .NET 3.5 SP1. In my app, I have satellite assemblies which are not in the same folder as the exe, and that causes me some trouble with FullTrust, as explained here. In order to solve that problem, I wish to use .NET 4.0 whose Code Access Security Policy should allow my sa...

Is the "message" of an exception culturally independent?

In an application I'm developing, I have the need to handle a socket-timeout differently from a general socket exception. The problem is that many different issues result in a SocketException and I need to know what the cause was. There is no inner exception reported, so the only information I have to work with is the message: "A conn...

Mysterious socket / HttpWebRequest timeouts

I have a great app for capturing shoutcast streams :-) . So far, it worked with a charm on dozens of machines, and never exhibited behaviour I found now, which is ultimately very strange. I use HttpWebRequest to connect to different shoutcast servers and when I connect two streams, everything's OK. When I go for third one, respon...

How can I retrieve monitor information?

I am trying to retrieve the monitor ID's as shown in the Windows display properties (#1, 2... etc), but I can't seem to find a way. I have tried using EnumDisplayMonitors as well as EnumDisplayDevices. They both return something like "\.\DISPLAY1". However, this number doesn't always match the number shown by Windows, especially when 2 v...

How to tie a background thread to the lifetime of an object?

I want to create a background thread that's owned by an object. When that object is no longer needed, so is its background thread. pseudo code of what I currently have: ResetEvent _isCanceled ResetEvent _hasWork ThreadSafeQueue _workItems Init() new BackgroundThread(ThreadLoop).Start() AddWork(work) _workItems.Enqueue(work) _ha...

How to reduce this IF-Else ladder in c#

This is the IF -Else ladder which I have created to focus first visible control on my form.According to the requirement any control can be hidden on the form.So i had to find first visible control and focus it. if (ddlTranscriptionMethod.Visible) { ddlTranscriptionMethod.Focus(); } else if (ddlSpeechRecognition.Visi...

Is the ASP.NET web.config file getting out of hand?

Heres something I've been pondering for a while ... Do you struggle with the size and the number of entries in the web.config file? Do you understand every element? Is it time for Microsoft to relook at how an ASP.NET site is configured, perhaps by splitting the web.config file into multiple files? ...

Textbox control in ASP.NET not to be part of a formview

I have to add a textbox inside a form that is composed of a lot of textboxes, and one button at the end. It has a datasource, all data is loaded in formload, and the button updates the values of the textboxes. The thing is: this particular textbox won't be in the datasource, I want to get this from the web.config, and I've already manage...

How to Lock a file and avoid readings while it's writing

My web application returns a file from the filesystem. These files are dynamic, so I have no way to know the names o how many of them will there be. When this file doesn't exist, the application creates it from the database. I want to avoid that two different threads recreate the same file at the same time, or that a thread try to return...

.NET IsValidXml Extension Method Performance

I have a legacy application that I inherited that passes a lot of XML around as Strings. I often need the ability to check if a String will be valid XML. What is the fastest and least expensive way to check if a string is valid XML in .NET? I'm working in .NET 3.5 and would most likely use this as an extension method (off of string) i...

IntPtr.Size shows OS version or .NET version?

Does the results of IntPtr.Size show the OS that the .NET app is running on or which version of .NET Framework that is running? If you have a 32-bit app running on a 64-bit machine using WOW, what will IntPtr.Size show (4 or 8)? ...

Changes to xml file not being recognized - ASP.NET

I read a xml file (myConfig.config) and provide it as an input to a CLR method. When I make changes to this xml file, it doesn't seem to be recognizing it. When this line throws an error, I always see the first version of the file as a part of the error message. In the config file properties, I have set Copy to Output Directory as Copy ...

Looking for downloadable demo of a .Net service accessed through a pure JavaScript client, without relying on IIS to serve the service.

I am told that the configuration below is possible, but have had significant difficulty in finding instructions on how to set it up. While I'm trying to muddle my way through this on my own, maybe stack-overflow knows of better sources for documentation: I am looking for a walkthrough, including a downloadable, working example, for sett...

When to address managed heap fragmentation

I was reading a blog entry by Josh Smith where he used a cache mechanism in order to "reduce managed heap fragmentation". His caching reduces the number of short-lived objects being created at the cost of slightly slower execution speed. How much of a problem is managed heap fragmentation in a managed language like C#? How can you diagn...

Using linq to combine objects

I have 2 instances of a class that implements the IEnumerable interface. I would like to create a new object and combine both of them into one. I understand I can use the for..each to do this. Is there a linq/lambda expression way of doing this? EDIT public class Messages : IEnumerable, IEnumerable<Message> { private List<Message> ...

Is the WCF REST Starter Kit dead in the water... now?

Looking at an older stackoverflow post (back in June 2009, http://stackoverflow.com/questions/1006309/is-the-wcf-rest-starter-kit-dead-in-the-water), a Microsoft employee said they were pretty close to releasing the next version of the Starter Kit. That was a looong time ago and... they haven't released one. So I'm asking again, Micros...

What's a good way to copy files from a PC to a Windows Mobile device?

I have a C# application running on a server, and it needs to copy files out to multiple Windows Mobile 5.0 devices. These devices are connected to the network directly via Ethernet-enabled cradles (so they are not connected to a PC via ActiveSync). What different options do I have for doing this? I know RAPI can do this, but I'm not s...

launch an application from HTML with arguments

Is there a way to allow an HTML file to open an application on the local computer and send that application arguments? We have an application that allows a user to set a link to an external application. We also provide a summary page in HTML (they usually interact with the application from outside the browser) with the link in HTML as w...

ObjectDataSource converts empty string to 01/01/01

Hi, I'm converting a project to use ObjectDataSources instead of SqlDataSources. I'm using text boxes for user input of dates. When these were left blank with a SqlDataSource, the value sent to the stored procedure was null, allowing me to get the right results from a query with no date specified. With the ObjectDataSource, a blank inp...

Generate exe in .Net

In .Net, you can generate byte code in memory, and presumably save the resulting program to a .exe file. To do the first step, I have the following test code adapted from http://www.code-magazine.com/Article.aspx?quickid=0301051 var name = new AssemblyName(); name.Name = "MyAssembly"; var ad = Thread.GetDomain(); var ab = ad.DefineDynam...