You searched for exceptions. We found 168 results in 0.156 seconds.

Overriding GetHashCode() C# Complex way or simple way?

The more I read the more confused I am from blogs, to MSDN, to other stackoverflow questions and responses. This article:...
Jon Skeet
people
quotationmark

To my mind, you should always override GetHashCode if you override Equals - otherwise you're violating the contracts of those methods. However, for mutable types, client code needs to be aware that if it does mutate a value used as a key... more

people

Asserting for equality anonymous types

I faced a problem asserting two anonymous types. What I've done so far I have unit test project which sees the internals of my project under test, so anonymous types are...
Jon Skeet
people
quotationmark

Even though the anonymous types are accessible in your test project, that doesn't mean they'll be used when you write new { ... }. If you look at actionResult.Value.GetType() and expectedActionResult.Value.GetType() I strongly suspect... more

people

C# Obtaining data from WebRequest not returning values

I have the following C# method that accepts a URL as an input and returns the text data that exists at that location: public string GetWebData(string uri) { string response =...
Jon Skeet
people
quotationmark

You're returning response immediately - even though the callback which assigns a useful value to response will only fire later. Do you understand how BeginGetResponse works? It would be worth studying the documentation and examples... more

people

Difference between await and ContinueWith

Can someone explain if await and ContinueWith are synonymous or not in the following example. I'm trying to use TPL for the first time and have been reading all the documentation,...
Jon Skeet
people
quotationmark

In the second code, you're synchronously waiting for the continuation to complete. In the first version, the method will return to the caller as soon as it hits the first await expression which isn't already completed. They're very... more

people

Why HttpListener couldn't start?

I am designing a http server using .NET. I basically use HttpListener to get http request from client. At the beginning, I have to specify the URL, and add that URL to...
Jon Skeet
people
quotationmark

I can think of two simple reasons this might be happening: You have something else which is already listening on port 80 (such as IIS) You don't have permission to listen on port 80 The exception should indicate which of these is the... more

people

How restart a thread, no pause nor sleep

I've searched around and I want to abort a thread and restart it, something who should be really simple but no one is answering. Basicly I have an user who conenct throught a...
Jon Skeet
people
quotationmark

I've searched around and I want to abort a thread and restart it, something who should be really simple but no one is answering. You can't - it's as simple as that. Once a thread has been successfully aborted (i.e. it really has... more

people

Reading a specific line with StreamReader

I have a problem with the stream reader. i want to read from a text file just one line. I want a specific line, like the seventh line. and i don't know how to. it's a function...
Jon Skeet
people
quotationmark

The simplest approach would probably be to use LINQ combined with File.ReadLines: string line = File.ReadLines("foo.txt").ElementAt(6); // 0-based You could use File.ReadAllLines instead, but that would read the whole file even if you... more

people

Convert Stream data to custom object in C#.net

I want to convert stream data from response stream into a custom object. I want to convert respose stream into custom object,I am following these steps. My code is as...
Jon Skeet
people
quotationmark

The trouble is that you're trying to deserialize an object when you've already read all the data from it just beforehand: readStream = new StreamReader(receiveStream); Console.WriteLine (readStream.ReadToEnd()); After those line, the... more

people

Boxed nullable underlying type can be cast to enum but boxed enum type can't be cast to nullable type

Boxed nullable underlying type can be cast to enum but boxed enum type can't be cast to nullable type. And similarly, Boxed nullable enum can be cast to underlying type but...
Jon Skeet
people
quotationmark

I think this is a subtlety of the unbox and unbox.any IL instructions. From ECMA 335, section III.4.32 (unbox operation - unbox.any is similar) Exceptions: System.InvalidCastException is thrown if obj is not a boxed value type,... more

people

The process cannot access the file because it is being used by another process error

here is my code: public static bool createFile(string dir) { dir="c:\\e.bat"; System.IO.File.Create(dir); if (System.IO.File.Exists(dir)) ...
Jon Skeet
people
quotationmark

You're calling File.Create at the start of the method - which is returning you a stream, which stays open. It's not clear why you're calling that at all, but I'd suggest just removing that line. You should also use a using statement, only... more

people