background preloader

.Net

Facebook Twitter

Simple Error Logging Util Class. Introduction This tip describes a simple exception/custom message logger which can be used to log Application Errors, Logical Errors, etc. in an easy manner. Background The importance of having a static mechanism to log these messages came up with below: Repeatedly coded Error logging can be eliminatedIO Errors, etc. needed to be handled while logging errors Using the Code Create the class and its implementation as below: For keeping Error Logs in a specific config. folder, I have used another class in which methods are being called from above to determine the Error Log's Location. In case while creating the error logging path, initially if it doesn't exist, it will create the config. folder to log the error.

Points of Interest This was quite useful to have this implemented for apps so it was then easy to identify runtime exceptions as well as logical error logging by our apps all in one place. AJAX DLL. Download demo Introduction AJAX DLL is a library developed using .NET for ASP.NET 3.0/3.5/4.0/4.5. It is used to call server side methods from JavaScript. You can pass the method parameter value from JavaScript. A parameter can be a variable or a Model object.

In the given example, I have used the parameter as a string variable, an array object and a Model class object. A benefit of this DLL is that you can use it at UserControl level, so if you have some method in UserControl and you want to call it via JavaScript, you can achieve it using this DLL. Using the Code It’s very simple to use Ajax DLL. Once a DLL has been added into your application, you need to place a line code in the Page_Load event as below: This code will register your page class in DLL with all your AJAX method(s) written in the page class, which are given in the image below. There are five optional parameters with the Ajax.AjaxMethod attribute: Method name: A method which you want to call from JS. Find the HTML code here: Bool To Content Converter. Introduction I've created a lot of bindings to boolean values that required a converter of some kind. And, I've found that a simple bool to object converter takes care of a lot of my problems.

At first, I would create a user control or converter for just about everything; I've seen a few other people go down that same path. Need to set the background image on a button based on some bool value of the selected item, write a bool to BitmapImage converter. Need to set a text color, based on the success of an operation, write a bool to Brush converter. That bool to Brush converter was originally a bool to SolidColorBrush converter, but as soon as I wrote that, I thought, that's way too specific. Switching that converter from solid color brush to just brush made me realize that I could have just done a BoolToObjectConverter and gotten rid of quite a few classes in the code base for the project we were working on. Background For this to be useful, you will need to know: The Code Using the Code. New .NET Debugging API Released.

Onward and UpwardKeith Ward, Editor in Chief, Visual Studio Magazine Blog archive New .NET Debugging API Released Microsoft's released a new .NET Framework managed library to help with debugging and crash dump analysis. It's a beta release, and is called Microsoft.Diagnostics.Runtime (abbreviated to ClrMD -- MD for "Memory Diagnostics"). It's available through the NuGet package manager. It works similarly to the SOS Debugging Extensions. According to a blog entry by Lee Culver, a developer on Microsoft's .NET Runtime team, it wasn't the original plan to release the library publicly.

Culver also noted that the library is a wrapper around CLR internal-only debugging APIs. The most basic thing you'd probably to with ClrMD is print out heap stats to the console. The blog also contains a code sample to help you learn by doing. Weekly Digest 11 - Jakub Chodounsky, Programmer. Functional Programming in C# 3.0 using Lambda Expression - Part 1. Introduction C# was born in an object oriented programming family and started evolving to adopt the characteristics from other programming languages as well the functional programming family. It laid its foundation to adopt functional programming since version 1.0 with delegates and some partial adoptions found in C# 2.0. Finally, it smartly adopts functional programming style with OO. In this article, I will explain how to write programs in a functional manner using C# 3.0.

If you are new to functional programming or do not know the benefits of it, read my two part articles, Introduction to Functional Programming using F# Part 1 and Part 2. Factors for Functional Programming Adoption As I explained in my article, Introduction to Functional Programming using F#, there are eight factors that need to be supported by a programming language for functional programming. I am going to explain how C# 3.0 adopts or satisfies these factors with necessary details.

Delegates Delegate type. Generics. Cumbersomeness Web.Config. People who are in .NET arena might encounter the plethora of xxx.config files, especially web.config. It is a required devil for placing any configuration settings for your applications. We should appreciate the effort taken by the engineers at Microsoft for introducing (at that time, Java’s configuration approach was very immature) and providing a declarative approach, centralized and optimistic way of configuring your .NET application of any size.

This has fitted well for applications written for simple purpose including training codes, in-house tools, etc. In a real-world, irrespective of small, medium or large scale, both Visual Studio and developers place lots of stuff on this mess surrounded by <, >, />, ” characters. When you see the web.config schema, it accommodates the following types of configuration for an application: Bit sleepy? There are machine wide settings that are overridden by the site and application wide settings too. In the above code, you see such mapping. Domain Specific Language using C# 4.0 - Part 1.

Hope you know what DSL (domain specific language) is. It is a programming language aimed for a particular domain with the users in that domain in mind. DSL is different from general purpose programming languages (C#, Java, Ruby, Python) in that DSL is limited to a particular problem domain whereas general purpose languages are made for addressing any kind of problems in the world. For example, your NANT build scripts and Unix shell scripts are some of the example DSLs. Yes, DSL is not new. A DSL can be created either on top of existing programming languages like C#, Ruby, etc., or created from scratch by using parser-generator tools like ANTLR, Irony.

In this article, I create a DSL for examination question paper in C#. The below diagram depicts the domain model for this domain. Exam Class Question Class The source code for AnswerSheet and Level are not required, since the class diagram represents them well. CodeProject. How to design exceptions. This article will teach you how you should design your exception classes. It’s a follow up to my previous article which told you what exceptions are and their intended usage.

Exception inheritance As C# is an object oriented language exceptions also use inheritance. You might wonder why since exceptions doesn’t benefit from inheritance if you view it from a strict exception handling view. Consider the following code: try { return userFetchedFromDb; } catch (DataException ex) { } It’s unlikely that you could return a User by catching DataException .

Try { return userFetchedFromDb; } catch (DataConnectionFailedException ex) { } You could have had a chance to recover from the exception. The only exceptions that are useful for exception handling is the most specific ones. So why do they exist then? Exception hierarchies allow you to categorize exceptions which makes it easier to log or notify when exceptions are caught. ApplicationException Conclusion Constructors YourException(string description) ASP.NET News and Articles For Lazy Developers. .NET: Run-time Serialization. Object Serialization in .NET. Piet Obermeyer and Jonathan Hawkins Microsoft Corporation August 2001 Updated March 2002 Summary: Why would you want to use serialization? The two most important reasons are to persist the state of an object to a storage medium so an exact copy can be recreated at a later stage, and to send the object by value from one application domain to another. For example, serialization is used to save session state in ASP.NET and to copy objects to the clipboard in Windows Forms.

Contents Introduction Persistent Storage Marshal By Value Basic Serialization Selective Serialization Custom Serialization Steps in the Serialization Process Versioning Serialization Guidelines Introduction Serialization can be defined as the process of storing the state of an object instance to a storage medium. When implementing a serialization mechanism in an object-oriented environment, you have to make a number of tradeoffs between ease of use and flexibility. Persistent Storage Marshal By Value Basic Serialization.