Showing posts with label Must Read. Show all posts
Showing posts with label Must Read. Show all posts

Saturday, November 29, 2008

The type initializer threw an exception

Can not see the Form in the Designer. "The type initializer threw an exception." error
I got a problem recently when one of the forms I created could not be opened in Designer. Error message was as brief as "The type initializer for "..." threw an exception.". I found a good advice from Microsoft Developer Support guy Keith Fink how to debug the problem here.
Here is the advice:
Usually this means that your constructor of a particular type is throwing an exception. One way to debug this is to use aseparate instance of Devenv.exe and attach to the instance where yourproject is open, and then open the inherited form that causes the problem.

In the instance of Devenv.exe that you are using to debug with, followthese steps.

1. Start Devenv.exe.2. Select Tools->Debug Processes.3. Select the other instance of Devenv (where your project is loaded), andclick Attach.4. Make sure to select Common Language Runtime, and uncheck Nativedebugging, and click OK.5. Click Close.6. Select Debug->Exceptions.7. Expand Common Language Runtime Exceptions->System.8. Select the System.TypeInitializationException.9. Under the "When the exception is thrown" section, select the "Break intothe debugger" option, and click OK.10. Switch over to the other instance of Devenv, and open the form so thatthe exception is thrown. When that happens the first instance of Devenvshould break on the line of code where the exception is thrown.

One more hint - in the Form code DesignMode property is useful (it'll tell you if your Form is loaded in designer).
Note that the DesignMode property should not be checked from within the constructor or from any code that the constructor calls. A constructor is called before a control is sited, and it's the site that determines whether or not a control is in design mode. DesignMode will also be false in the constructor. I personally like to put it into Form_Load event (Form_FormClosing if you want to do something like logging on form close).
Example:
...
if(!this.DesignMode)
{
// chek authentication or something else
}

And finally a good article about
Design-time integration of controls.

10 Articles you should Read

10 .Dot net articels you should READ
Multi-Lingual Language Translations for ASP.NET
Here are a few free (paid for by me) language translations of common software terms for use in your multi-lingual ASP.NET application. This is particularly helpful if you want to create a list of available languages in Spanish, German, Chinese, etc... The language translation spreadsheet has generic term translations for Spanish, English, German, Italian, French, Chinese-Simple, and Japanese. The language name translations also includes Dutch, Korean, and Russian.
Dependency Injection using Spring.NET
Spring.NET is one of the popular open source framework ported from Java platform. It offers lot of functionality and in this article I will discuss about Dependency Injection and how it is supported in Spring.NET
Obfuscation and Packaging of .NET Applications via Compressed Embedded Assemblies
Shows a technique for embedding all the assemblies for an application as compressed, embedded resources into a single stub loader executable, extracting, decompressing and loading into the AppDomain at startup.
WPF & PowerShell - Part 7 (Sharing Hosts)
Well here we are at the end of a week of WPF. We've learned how to create basic, simple user interactive interfaces. We've seen a brief glimmer of the golden UI layer that is WPF, and have seen how we can use PowerShell to add easy interactivity to XAML. You've seen tricks to help you work your way through .NET code, and help you unwrap the mysteries of WPF. We've seen how we can use PowerShell's list processing technology allows for simple binding to WPF's controls, and how WPF applets can help you present a simple front ends to PowerShell functionality. We've gotten a very brief taste of what the pipeline can bring to User interfaces, and we've showed you how to make controls that run in the background so you can build your control in PowerShell and still use PowerShell.
Patterns in Practice - The Open Closed Principle
This is the first installment of a new MSDN® Magazine column on software design fundamentals. My marching orders are to discuss design patterns and principles in a manner that isn't bound to a specific tool or lifecycle methodology. In other words, my plan is to talk about the bedrock knowledge that can lead you to better designs in any technology or project.I'd like to start with a discussion of the Open Closed Principle and other related ideas popularized by Robert C. Martin in his book, Agile Software Development, Principles, Patterns, and Practices. Don't be turned off by the word "agile" in the title, because this is all about striving for good software designs.
How to Find Memory Leaks With CLRProfiler
We all know managed code can have memory leaks. You can find a good example here: A .NET memory leak you did not think about. Microsoft provides us with the CLR Profiler, an open source tool for analyzing the behavior of your managed application, which you can download here. It contains very good documentation about the different functions of the tool, however I still find it a bit hard to start with, so here is a simple step-by-step example of how to use it.
Animation in-depth with Silverlight 2.0 Beta - Part Four
In this example I'll show you how animations can be performed using a VideoBrush. This is one of the examples that attracts the users attention by completing the animation at the right time. The video will be clipped and rotated during the animation.
IronRuby on Rails. Microsoft makes it happen.
Now... No more doubts about Open Source Support by Microsoft. The first ever Open Source Project comes live now.
Mr. John Lam, the person behind IronRuby has provided more information on his blog here...
http://www.iunknown.com/2008/05/ironruby-and-rails.html Here are the Highlights of his blog.
Optimization Tips: Using HTTP Compression
I know it has been a few weeks since the last installment in this series, and with TechEd on the horizon it'll probably be a couple 'til the next, but as long as there is some time in between let's explore another area of performance optimization with the RadControls for ASP.NET AJAX. This week, we're going to take a look at HTTP compression and how this simple technique can deliver a valuable performance boost to your website.
ASP.NET Memory: Thou shalt not store UI objects in cache or session scope
Surprisingly the issue I wrote about in "the eventhandlers that made the memory baloon" (Jan 2006) is something that still happens very frequently, I reference it in cases at least a few times a month. Just this last week I had different variations of it crop up in different cases so in this post I will show a different variation, what to look out for and how to identify it.

Monday, November 24, 2008

Reference site for .NET

Some useful and important forums reference sites

ASP.NET forums
www.forums.asp.net

VB Forums
www.vbdotnetforums.com/
www.a1vbcode.com/vbforums/

C#.NET forums
www.c-sharpcorner.com/
www.mastercsharp.com
www.csharphelp.com/
www.csharp-source.net/
www.developerfusion.com/

Sunday, November 23, 2008

.NET Framework

Microsoft has introduced .NET with the intention of bridging the gap in interoperability between applications. It is designed to make significant improvements in code-reuse, code-specialization, resource management, multi-
language development, security, deployment and administration.
Components of .NET Framework
.Net Framework base classes
.Net class library that works with any .net language such as VB.NET or C#. This class library is built on the object oriented nature of the runtime. It provides classes that can e used in code to accomplish common programming tasks.
Common Language Runtime (CLR)
The CLR is the most essential component of the .NET framework. As like java having its on runtime environment (JRE – java runtime environment), .Net having its own as CLR. Runtime environment basically provides path with which the program can be executed.

The CLR runtime provides functionalities, Such as:

Exception handling
Security
Debugging & Version support to any
language that supports it.

Features provided by CLR:
Automatic memory management
Standard type system
Language
interoperability
Platform independence
Security management
Type safety

Managed Code

The code that is developed with a language compiler that targets the CLR is called Managed Code

Unmanaged Code

The code that is developed without considering the convention and requirements of the CLR is called Unmanaged Code. Unmanaged code runs and executes in CLR with minimal services.For example: Unmanaged code may run with limited debugging and without garbage collection process.
Class LoaderClass loader loads the code in the memory.

Garbage Collection

The automatic memory management scheme employed by the .net framework is called Garbage Collection. The garbage collector continuously traces the out of scope objects in the background and identifies objects that no longer have references.Because the garbage collector is always running, you do not have to explicitly destroy the objects, it will automatically cleaned when you are finished working with them.You can also force the garbage collector to run using System.GC.Collect() method.