System.ComponentModel.Win32Exception: Access is denied Error

Make sure your application pool identity account on your server has permissions to start that service. It works on your ASP.NET Development Server because it runs under your user account (admin) In a default IIS configuration, this account is Network service or ApplicationPoolIdentity (depending on IIS version) and usually cannot manage services. So, change the … Read more

What is the purpose of the vshost.exe file?

The vshost.exe feature was introduced with Visual Studio 2005 (to answer your comment). The purpose of it is mostly to make debugging launch quicker – basically there’s already a process with the framework running, just ready to load your application as soon as you want it to. See this MSDN article and this blog post for more information.

Parsing CSV files in C#, with header

Let a library handle all the nitty-gritty details for you! 🙂 Check out FileHelpers and stay DRY – Don’t Repeat Yourself – no need to re-invent the wheel a gazillionth time…. You basically just need to define that shape of your data – the fields in your individual line in the CSV – by means … Read more

Categories c#

How do I restart my C# WinForm Application?

Unfortunately you can’t use Process.Start() to start an instance of the currently running process. According to the Process.Start() docs: “If the process is already running, no additional process resource is started…” This technique will work fine under the VS debugger (because VS does some kind of magic that causes Process.Start to think the process is … Read more

C# switch on type

See gjvdkamp’s answer; this feature now exists in C# I usually use a dictionary of types and delegates. It’s a little less flexible as you can’t fall through cases, continue etc. But I rarely do so anyway.

Styles.Render in MVC4

It’s calling the files included in that particular bundle which is declared inside the BundleConfig class in the App_Start folder. In that particular case The call to @Styles.Render(“~/Content/css”) is calling “~/Content/site.css”.

Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”

Yes, the first means “match all strings that start with a letter”, the second means “match all strings that contain a non-letter”. The caret (“^”) is used in two different ways, one to signal the start of the text, one to negate a character match inside square brackets.

Specified cast is not valid.. how to resolve this

Use Convert.ToDouble(value) rather than (double)value. It takes an object and supports all of the types you asked for! 🙂 Also, your method is always returning a string in the code above; I’d recommend having the method indicate so, and give it a more obvious name (public string FormatLargeNumber(object value))

Categories c# Tags