Skip to main content

Posts

Why Visual Studio hangs

Every once in a while, VS seems to take forever to display a screen to the point that it seems to hang. Most of the time, it hangs, while accessing Fonts and Colors page in Tools/Options dialog. The issue is not that there is some weird code that executes very slowly. It happens that this page is implemented using .NET components. Now the majority of VS is built with native code and during most of its execution,, the CLR is never loaded. However, when the user accesses one of these features, the CLR must be loaded, before we can begin executing the relevant IL. It is this process that is time-consuming and annoying to the user. There are two problems for the users here: first, there is no feedback during loading of the CLR; second: the problem can occur multiple times within a single session of VS. I am trying to figure out the reason for this second issue. Let me know, if any of you knows.

Optional Parameter issue with COM and C#/VB

As we all know, C# doesn't support optional parameters(till framework 3.5) whereas VB does.In the same way, COM components don't support parameter overloading , so for each value in a parameter list, we've got to pass in something, even if it does nothing. Moreover, COM parameters are always passes by reference , which means we can't pass NULL as a value. In VB 2005, this is not really as issue because it supports optional parameters and we can just leave them out. But C# doesn't support this, so one have to create object variables and pass them in. See following code sample: u sing Microsoft.Office.Core; u sing Microsoft.Office.Interop.Excel;  // Must have office installed Application NewExcelApp = new Application; NewExcelApp.Worksheets.Add();       // This will not compile So, as a workaround, the Type.Missing field can be used and this field can be passed in with the C# code and the application will work as expected.  Check it in below code sni

Making assembly visible to a COM component

Following steps are necessary to make an assembly visible to a COM component: Set the Register for COM option under the build configuration Set the ComVisible attribute to true for each class you want exposed Set the ComVisible attribute to false for any class members you want hidden Set the ComVisible attribute to true for any class members that you want visible CodeProject

Using frequently build assembly in another applications (.Net)

Assume that you are creating a strong named MyAssembly that will be used in several applications. The assembly will be rebuilt frequently during the development cycle. But one must ensure that every time MyAssembly is rebuilt, it works properly with all applications that use it. So, in order to obtain this, we are required to configure the computer on which we develop the assembly such that each application uses the latest build of MyAssembly. To accomplish the above task, take the following action: To point to the build output directory for the strong named assembly, create a DEVPATH environment variable Add the following element to the machine configuration file:   <developmentMode developerInstallation="true"> . T his element tells the CLR to use DEVPATH to locate assembly. CodeProject

What is a serviced component?

A services component is a .Net component that uses component services of COM+, such as object pooling, transaction management etc. It executes within the managed execution environment of the .Net framework and shares its context with a COM+ application. It enables context sharing between COM+ and .Net framework classes. A serviced component is creates by defining  class that directly or indirectly derives from the ServicesComponent class. It utilizes COM+ services by using attributes of the System.EnterpriseServices namespace. A serviced component should be registered before it can access the component services of COM+. The following three types of registrations are used to register a serviced component: Manual registration: The .Net Framework Service Installation (Regsvcs.exe) tool is used to manually register an assembly containing a serviced component. Manual registration is used for design-time testing to find out the error types that may occur at runtime. Dynamic registration:

Covariance and Contravariance feature of .NET 4.0

Hi, I'll consider below class hierarchy throughout this explanation: class Account { } class Savings : Account { } class Current : Account { } Now lets begin with Example 1 : class Program { delegate T MyDel <T>(); static void Main( string [] args) { MyDel < Savings > objSavings = () => new Savings (); MyDel < Account > objAccount = objSavings; } } The code shown in  Example 1 will not work in versions prior to 4.0. But if you change generic parameter T to OUT T in 4.0, then this assignment compatibility work via CoVariance . Now check this 4.0 code in Example 2: class Program { delegate T MyDel <out T>(); static void Main( string [] args) { MyDel < Savings > objSavings = () => new Savings (); MyDel < Account > objAccount = objSavings; } } The only change in  Example 2 is additio