YATB (Yet Another Tech Blog)

Click on the window or control
Right click for properties
Click the Events (looks like lightning icon) button
Select the list of events to generate an event handler

Read more...

§225 · November 25, 2009 · C#, DotNet · Comments Off ·


Microsoft really sucks. Even their DotNet CLR runtime error reporting sucks. Last week, a user in London called me and reported a startup problem with the service I support. I could see the error in the event log as:
EventType clr20r3, P1 ripgrcubeaggregatoranalytic.exe, P2 3.3.0.2, P3 46267b76, P4 log4net, P5 1.2.9.0, P6 42a6f2e9, P7 259, P8 0, P9 system.typeinitialization, P10 NIL

This error message is completely completely utterly useless. Somehow this runtime error even avoided getting trapped by my service’s unhandled exception handler.
After endless iterations of testing with a previous version followed by more testing, I finally tracked down the cause of the problem to the London user’s messing up of the service’s App.Config file. He put in a one byte code- which invalided the entire App.Config xml- and threw the DotNet application into a fit.
So if you see this runtime problem, first check the App.Config.

Read more...

§76 · May 11, 2007 · C#, DotNet, Windows · Comments Off ·


Keep up to date with Microsoft’s Dynamic Language Runtime.

Read more...

§159 · May 2, 2007 · DotNet · Comments Off ·


I was confronted with a problem today- to get the column definitions for a database table in C#.  While I already had the C# code to load data from a database, when I inquired into the maximum length of a DataColumn object, the maximum length invariable read -1, even for a string type column.  I looked up MSDN- which led me to investigate the DataAdapter.FillSchema() method- which seemed to load the metadata associated with a DataTable.
With the code below, it seemed that FillSchema() performed as advertised.  At the completion of its call, the passed in DataTable contains the maximum length of the table columns.   Good going!
DataTable dummyData_ = new DataTable();
string strQuery = "select * from MDS_REFERENCE_POOL";
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = strQuery;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
 
adapter.SelectCommand = cmd;
adapter.Fill(dummyData_);
adapter.FillSchema(dummyData_, SchemaType.Source);
conn.Close();

Read more...

§158 · April 30, 2007 · C#, DotNet · Comments Off ·


Learning something new everyday!  Last week, my computer hard drive became toast.  Fried.  Apparently, I had been pushing the disk beyond its performance specs.  It finally failed last week- and died a horrible death.  Unfortunately, it also took along one of my project’s source code along with it.  And I had no backup!
However, I do have the compiled exe on my client’s server.  And I do remember that you can recover your source code from a .NET exe.   I googled for .net decompilers- and sure enough, I came across an extremely rad tool on Lutz Roeder’s site.  Using Lutz Roeder’s Reflector, I was able to regenerate VB and C# code from my .Net assembly (just an exe).
Now checking out Lutz Roeder’s links, I see he has written more tools for .Net.  One I’m going to check out is – CodeMetrics-  which again looks pretty rad.

Read more...

§64 · March 23, 2007 · C#, DotNet · Comments Off ·


.Net assembly exposed as a COM component
Something interesting came up today. It’s possible to expose a .Net assembly as a COM accessible object by using the RegAsm tool.   By default, always use RegAsm with the /codebase option- otherwise, at runtime, the client will choke on a cryptic ‘File Not Found’ error.  RegAsm inserts the proper entries for the .Net assembly into the registry for COM-compliant tools to examine and invoke.  Also, for runtime discovery tools like VBA and VB6, RegAsm can generate a typelib such that these tools can have at compile time access to the .Net assembly’s exposed methods.
Since COM is the invocation and communication layer, once the .Net assembly is registered as a COM object, it can be invoked just like any COM object.
Updating SQL Views
I didn’t know it’s possible to update a View- until today.  Astounding!  This means SQL Server breaks up the components of an update- down into the View’s constituent tables.  That’s seriously cool.

Read more...

§61 · February 27, 2007 · C#, DotNet, SqlServer · Comments Off ·


While attempting to implement the generic IEnumerable interface, I encountered the same maddening compile time error over and over again:
“error CS0536: ‘testEnumerator.MyList2′ does not implement interface member ‘System.Collections.IEnumerable.GetEnumerator()’. ‘testEnumerator.MyList2.GetEnumerator()’ is either static, not public, or has the wrong return type.”
Here is my test code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
 
namespace testEnumerator
{
S2    public class MyList1 : IEnumerable
S2    {
S4        private List items_ = new List();
 
S4        public MyList1() {}
 
S4        public void AddItem(T i)
S4        {
S2S4            items_.Add(i);
S4        }
 
S4        public IEnumerator GetEnumerator()
S4        {
S2S4 return items_.GetEnumerator();
S4        }
S2    }
 
S2    public class MyTest
S2    {
S4        static public void Main(string[] args)
S4        {
S2S4            MyList1 m = new MyList1();
S2S4            m.AddItem("test1");
S2S4            m.AddItem("test2");
S2S4            m.AddItem("test3");
S4       }
S2  }
}
Fortunately, googling found me someone else who had encountered the same problem months earlier. The author correctly identified that the generic IEnumerable interface inherits from the non-generic IEnumerable interface. This means that in order to implement the generic IEnumerable interface, one must also implement the non-generic IEnumerable interface. Who [...]

Read more...

§147 · January 5, 2007 · C#, DotNet · Comments Off ·


Interface can inherit from another interface
Interface I1
S2 Sub method1(ByVal i As Integer)
End Interface
 
Interface I2
S2 Inherits I1
 
S2 Sub method2(ByVal j As Integer)
End Interface
 
Interface I3
S2 Sub method3(ByVal k As Integer)
End Interface
To implement a class using Interface I2 and I3:
Public Class MyClass
S2  Implements Interface I2, I3
S2 Sub method1(ByVal i As Integer) Implements I1.method1
S4  …
S2 End Sub
 
S2 Sub method2(ByVal i As Integer) Implements I2.method2
S4 …
S2 End Sub
 
S2 Sub method3(ByVal i As Integer) Implements I3.method3
S4 …
S2 End Sub
 
End Class

Read more...

§53 · January 4, 2007 · DotNet · Comments Off ·


For C#, VB:
Finalize- a function defined for a class that gets called by the Garbage Collector when it cleans up the object. Unlike a destructor in C++, the timing of the Garbage Collector’s call to a class’ Finalize is completely unpredictable. Also, members inside a class should be left for the Garbage Collector to deallocate. The most likely usage of a Finalize is to release usage to a shared resource like a file or a database connection.
Example VB usage:

<br />
Public Class MyClass<br />
S2<br />
S2 Protected Overrides Sub Finalize()<br />
S2<br />
S4   myFileStreamWriter.Close()<br />
S2 End Sub<br />
…<br />

Sealed- this keyword is equivalent to the keyword “final” in Java. It tells the compiler to prevent users from inheriting from this class. A similar keyword is missing in C++ although the same restriction can be created by making the class constructors private- such that child classes cannot access the constructor- thereby creating a compile-time error.
The standard party line says to use sealed classes if there are only static methods and properties on a class. Why? If a class contains only static members (methods and members), then that class is clearly not meant to be inherited.
The Sealed keyword is NotInheritable [...]

Read more...

§52 · January 4, 2007 · C#, DotNet · Comments Off ·


That’s the new word of the day: CLSCompliant. (Past new words of the day include such notables as threadsafe, reentrant, and typesafe.) What’s CLSCompliant and where does it appear? That word popped up when I instructed VS2005 to perform a code analysis on my project. The first warning it flagged was my project was not marked ‘CLSCompliant’ by setting CLSCompliantAttribute to true.
First of all, what is CLSCompliant? From MS’s website- CLSCompliance means compliance with the set of rules that all .Net languages must follow in order to allow cross language interoperability. These rules cover everything from allowed data types to variable name uniqness etc. Cross language interoperability means you can create classes in one language and use in anohter.
CLS stands for Common Language Specification.
To publicize to the compiler and the world that your assembly or class is CLS compliant, tag the assembly or class with the CLSCompliantAttribute.
In C#:
using System;
// Assembly marked as compliant
[assembly: CLSCompliantAttribute(true)]
// Class marked as compliant
[CLSCompliantAttribute(true)]
public class MyCLSclass
{
}
In VB:
Imports System
< Assembly: CLSCompliant(True) >
< CLSCompliant(True) > _
Public Class NewClass
< CLSCompliant(False) > _
Public Sub NotCompliant(ByVal someNumber As SByte)

Read more...

§51 · January 4, 2007 · C#, DotNet · Comments Off ·