.net

REST in WCF -- PUT and DELETE return "Forbidden"

I created a REST webservice in WCF that originally used POST to perform any inserts and deletes. Mostly out of curiosity, I decided to change the insert to a PUT and the delete to a DELETE. While this worked fine on my local machine (using the built-in VS2008 webserver), I'm getting this error when trying to target an actual server dep...

What is the syntax for initalizing a string with a block of text in .NET?

I'm writing a unit test and can't remember the syntax for initializing a string with a large block of formatted text. string _testData = "a couple screens worth of text data here and I need to preserve the formatting such as line breaks, etc."; ...

The difference between implicit and explicit delegate creation (with and without generics)

See the four lines in the Go() method below: delegate void Action<T>(T arg); delegate void Action(); void DoSomething<T>(Action<T> action) { //... } void DoSomething(Action action) { //... } void MyAction<T>(T arg) { //... } void MyAction() { //... } void Go<T>() { DoSomething<T>(MyAction<T>); // throws compiler...

How do I make my Linq to Sql class IEnumerable

How do I make my Linq to Sql class IEnumerable or an object IEnumerable in C# 3.0 ...

Determine local culture of a PC without creating an application

Hi, Is there any way to determine the local culture of a PC (such as en-US) without running an application? I tried looking in Control Panel | Regional Settings (running WinXP), but I don't know how the choices there map to the PC's culture. I'm looking for a solution that doesn't require creating an .exe, such as running a command fr...

OpenProcess for PID owned by "NT AUTHORITY\SYSTEM"

I am trying to open a process handle in C# using the OpenProcess function as follows: IntPtr hProcess = OpenProcess(0x410, false, pid); where pid is the process ID of the process I would like to open. When called on a PID whose user is "NT AUTHORITY\SYSTEM" (on Vista x64), the above call fails, with an "Access Denied" error. How do ...

Measure performance bottlenecks in a library

In my website I have a rather complicated business logic part encapsulated in a single DLL. Because CPU usage hits the roof when I call certain methods of it I need to measure and optimize. I know about the performance profiler, but I don't know how to set it up for a library. Furthermore I don't seem to find any usefull resources about ...

How do I tell if a type is a "simple" type? i.e. holds a single value

typeof(string).IsPrimitive == false typeof(int).IsPrimitive == true typeof(MyClass).IsClass == true typeof(string).IsClass == true typeof(string).IsByRef == false typeof(MyClass).IsByRef == true I have a method that instantiates a new instance of T and, if it's a "complex" class, fills its properties from a set of source data values. ...

Why would ASP.NET not be able to find asp:UpdateProgress ?

Basically I am upgrading from 1.1 to .NET 3.5 SP1 and replacing an old .NET 1.1 WebForms application with its newer .NET 3.5 version. I run the .net 3.5 sp1 installer (dotnetfx35setup.exe) I run the crystal reports redistributable installer I set up a new application pool I set up a new website using the directory with the new files, u...

Will the .NET GC mess with an abandoned object executing a method asynchronously?

In .Net, suppose I instantiate an object that starts an asynchronous process (using Delegate.BeginInvoke on one of its methods), then abandon the object by setting the reference to it to null or allowing it to go out of scope. Will the Garbage Collector attempt to collect the object while the asynchronous process is in progress? If not, ...

Incorets script proxy generating for Web Services Asynchronous WebMethods

I have created an asynchronous web method in one of my web services, which I am trying to call from Javascript. The problem is that the proxy script generated for the client includes two methods instead of one. For each asynchronous web method I define a BeginXXX and EndXXX, where XXX is the method name. When calling the web service from...

Interrupt an active screensaver programatically?

REASON: I'm working on an emergency alert application that needs to display information on a desktop. When the client receives an alert, it pops up a window. If a screensaver is active or the monitor is in standby the alert will not be visible. I'm wondering if it's possible to wake the computer up via some sort of programatic mouse m...

C#, Windows Forms, Best/min fit window to contents

I have a form with some controls. (Actually, this is a sort of ongoing problem.) Some of the forms I have had are resizable, some are not. Regardless, when the form is displayed, it would be nice to have it appear in the "minimum" size needed. Other Windowing toolkits, such as wxWidgets (wxWindow::GetMinSize) and Qt (QWidget::minimumSize...

Write file from assembly resource stream to disk

I can't seem to find a more efficient way to "copy" an embedded resource to disk, than the following: using (BinaryReader reader = new BinaryReader( assembly.GetManifestResourceStream(@"Namespace.Resources.File.ext"))) { using (BinaryWriter writer = new BinaryWriter(new FileStream(path, FileMode.Create))) { l...

Setting credentials for a WCF application?

I've written a simple Application that utilizes WCF to communicate between client and server. When I run it locally it works fine, however when I run the server and client on two different boxes I get the following exception: Unexpected error occured, while getting the group names from the VDN server System.ServiceModel.Security.Securit...

C# 3.0: Find SMTP Servers within a Domain

I'm using C# 3.0 and the System.DirectoryServices namespace (not the newer System.DirectoryServices.AccountManagement namespace of .NET 3.5). How can I find all of the SMTP Servers on the local domain? Is this even possible? Is there another way to accomplish this? ...

How do I compare a generic type to its default value?

void Get<T>(Action<T> createObject) { T obj = createObject(); if(obj == default(T)) return obj; // .. do a bunch of stuff return obj; } Compiler error: Operator '==' cannot be applied to operands of type 'T' and 'T' How do I do this properly? ...

Getting null terminated string from System.Text.Encoding.Unicode.GetString

I have an array of bytes that I receive from an external entity. It is a fixed size. The bytes contain a unicode string, with 0 values to pad out the rest of the buffer: So the bytes might be: H \0 E \0 L \0 L \0 \0 \0 \0 \0 \0 ... etc I'm getting that buffer and converting it to a string like so: byte[] buffer = new byte[buffSize...

Can a Silverlight application authenticate versus a local LDAP/ActiveDirectory Server

If I have an externally hosted application (www.outside.com) outside the firewall but users within a company wanted to be able to enable LDAP authentication against their local (behind the firewall) AD server (acting as LDAP) or other LDAP server (call it ldap.inside.com), how would this be done. It seems technically possible in that wh...

Why is Microsoft not developing a Halo-like next gen title using C#?

The question might look subjective but considering Microsoft: Owns the Xbox 360 platform Owns the Windows platform Have their own game studio (MGS) Own other 3rd party developers Is a major publisher makes me wonder why Microsoft doesn't push their flagship language to prove that not only you can cut down significant development time...