Upcoming Speaking Engagements

At the current time my speaking schedule for the rest of the year looks like:

  • Tulsa Tech Fest – October 14th (The day
    after my birthday)
    • NUnit Extensibility – Creating custom assertions for NUnit
    • Zero Cost .NET – How to use nothing but free tools to create a powerful .NET development
      environment.
  • Dallas .NET User Group – December 14th
    • Black Belt XML – XmlReader, XmlNamespaceManager, Namespaces, and why it all matters.

I’m beginning to put together my schedule for 2007.  If you would like to have
me speak at your user group, then drop me a line
and let me know
.

DFW BizTalk User Group – Interested?

I’ve been having conversations with several people working with BizTalk in the DFW
area recently and we are trying to guage interest in the forming of a BizTalk User
Group.  To start with we would probably begin as a Special Interest Group (SIG)
of the Dallas .NET User Group.  I’ve had preliminary conversations with their
President and he is amiable to the idea.  What I need to know is who out there
would like to be a member of such an organization?

If you are interested, drop me an email using the contact link on my blog and let
me know or leave a comment here.

BizTalk 2006 Recipes Book Now Available

BizTalk Server books are in short supply.  And finding one that really helps solve real world problems is event harder to find. 

A new BizTalk book is now available.  It's called BizTalk 2006 Recipes and is currently available on Amazon.com for around $38.

I was fortunate enough to get to work with the authors of this book as a Tech Reviewer. This book covers BizTalk from end to end and is a must have for any BizTalk project!

FileSystemWatcher Class

I just found the FileSystemWatcher class in the System.IO namespace. It provides the functionality to listen on the file system for changes on a file or directory. The class fires a couple of events: Changed, Created, Deleted and Renamed.
I didn’t know of this class until now. I always thought one had to write a service to accomplish something […]

Getting into the Flow

I came across an entry on Michael Buffingtons blog this evening where he discusses the techniques he uses to ‘get into the flow’. Reading his suggestions (such as a cold office, limiting his number of apps etc.) I started to think about how I go about focusing my mind to accomplish the job at hand.
At […]

log4net Database

I was recently introduced to log4net by
Ed Kisinger of EqSquared.com and absolutely
love the project.  I’ve previously used to Logging Application Block inside Enterprise
Manager for my logging, and would again if I was using the rest of EntLib, but log4net
fills the wonderful point where you may not want to take on all of EntLib and still
have excellent logging.

log4net abstracts the actually logging on messages from the
location that a log will be stored.  As such it is easy to change from file logging,
to UDP network logging to Database logging, all without touching the code which actually
logs.  Fantastic idea!  The Appender model, as they call this, includes
many excellent Appenders right out of the box.

In particular, I wanted to use to AdoNetAppender to log my messages
to a database.  Easy enough, the simple example included in the AdoNetAppender
documentation logs the most basic of information.  But as you dig deeper into
what information log4net can store, you begin to realize how oversimplified
this structure really is.

It would be a reasonable thing to say that I can sometimes be
a bit of a perfectionist.  As such I spent this morning creating a database structure
capable of holding all of the log4net information, properly normalized to the third
normal form.  If you would like to be able to store any information available
from log4net when logging to a database, then feel free to take this structure and
adapt it to your needs.

The only personalized piece of this database at the moment is
the inclusion of a column for storing a property called InstanceId.  As I work
with BizTalk on a regular basis, and love Scott
Colestock’s BizTalk Deployment Framework
, I included a column for the Orchestration
instance id which his Serializable
log4net extension includes.

Download
Version 1.0 of log4net Database

The Crucial "Gotcha" of the Business Rule Engine


I always remember that there’s a big “gotcha” for using the Business Rule Engine (BRE) within BizTalk, but I always forget what it is — until it gets me.


Most of the time, we’re passing a message, a.k.a. an XML document, into the BRE. It’s quite handy that we can reference the same .XSD schema created in BizTalk when setting up our BRE vocabulary. Just remember this when you create a vocabulary element:



The document type must be set to the fully qualified document type (for example, MyProject.MyMessage). The default is the schema file name with no extension.


…which generally means that the default is the document name/type in your BizTalk project, but without the project qualifier. Everything will test just fine in the Designer. You’ll flip back over to your Orchestration, drop in a Rule Shape … and you find that you can’t assert any facts into the engine! At that point, while you can edit the vocabulary, you can’t edit a specific element’s type. You have to delete the element and recreate it. Big pain.

So when creating your vocabulary, flip back to your BizTalk project, click on the schema you’re using, click on the "Fully Qualified Name" property, hit Tab, copy the fully qualified name, Alt-Tab back over to your Composer screen and paste. In fact, this is one of those things you’ll probably have on Notepad somewhere for quick reference.

How to call C++ DLL from ASP.NET (C#) code?

The problem: normally, you use DLLImport and P/Invoke. However, it only works if DLL is loaded. For normal program you can put it into the same folder as managed executable, and everything will be just fine. Not for ASP.NET, which is compiled into an obscure location, which you would not want to mess up with. Other places like System32 folder are also not a good choice. So, what can you do?

The solution: Actually, people already thought about this problem and found some solutions. See, for example, here. Some people even suggest to create the class dynamically, putting the correct DLLImport attribute value using the reflections. (See. here). However, the reality is much simpler. The only real problem is to ensure that DLL is loaded. One way to do that, is to create a special folder and put it into the PATH environment variable. If you don’t like that, you can use the same solution, I did lately, simply load DLL ahead using LoadLibrary. Once it’s in memory, the system will not look around on disk and will simply use it.

Code fragments (C#):

Declaration of LoadLibrary:

 [DllImport(“kernel32.dll”)]
 public static extern IntPtr LoadLibrary(string lpFileName);

 [DllImport(“kernel32.dll”)]
 public static extern IntPtr FreeLibrary(IntPtr library);

Declaration of your functions from C++ DLL:

 [DllImport(“SampleLib.dll”, PreserveSig = true, CharSet = CharSet.Unicode)]
 public static extern UInt32 DoStuff(…parameters…);

Loading DLL:

 String DLLPath;
 DLLPath = … full path to your DLL…
 IntPtr lib = LoadLibrary(DLLPath);
 … now, if lib is equal zero, you failed…

Now you can call it:

 UInt32 res = DoStuff(…);

And after you did what you wanted, don’t forget to free it:

 FreeLibrary(lib); // check HRESULT, if that bothers you 

—–

Added 3/8/07: Thanks to PSP (see his comment below), an additional important point is uncovered: DLLImport seems to increase refcount on the library just like LoadLibrary() does. Hence, it looks like you will need to call FreeLibrary() twice. Very odd, but looks real. I wonder, who calls FreeLibrary() when LoadLibrary() is not used?

How to call C++ DLL from ASP.NET (C#) code?


The problem: normally, you use DLLImport and P/Invoke. However, it only works if DLL is loaded. For normal program you can put it into the same folder as managed executable, and everything will be just fine. Not for ASP.NET, which is compiled into an obscure location, which you would not want to mess up with. Other places like System32 folder are also not a good choice. So, what can you do?


The solution: Actually, people already thought about this problem and found some solutions. See, for example, here. Some people even suggest to create the class dynamically, utting the correct DLLImport attribute value using the reflections. (See. here). However, the reality is much simpler. The only real problem is to ensure that DLL is loaded. Once way to do that, is to create a special folder and put it into the PATH nevironment variable. If you don’t like that, you can use the same solution, I did lately, simply load DLL ahead using LoadLibrary. Once it’s in memory, the system will not look around on disk and will simply use it.


Code fragments (C#):


Declaration of LoadLibrary:



 [DllImport(“kernel32.dll”)]
 public static extern IntPtr LoadLibrary(string lpFileName);


 [DllImport(“kernel32.dll”)]
 public static extern IntPtr FreeLibrary(IntPtr library);


Declaration of your functions from C++ DLL:



 [DllImport(“SampleLib.dll”, PreserveSig = true, CharSet = CharSet.Unicode)]
 public static extern UInt32 DoStuff(…parameters…);


Loading DLL:



 String DLLPath;
 DLLPath = … full path to your DLL…
 IntPtr lib = LoadLibrary(DLLPath);
 … now, if lib is equal zero, you failed…


Now you can call it:



 UInt32 res = DoStuff(…);


And after you did what you wanted, don’t forget to free it:



 FreeLibrary(lib); // check HRESULT, if that bothers you