Feeds:
Posts
Comments

Archive for August 24th, 2011

I have had a bit of trouble to get ntmlHTTP running correctly on our servers. In response to my ticket on RiaForge, Nick Harvey clarified the dependence of the DLL on .NET version 3.5 (or higher, I suppose). I’m not a Windows nor a .NET specialist, and I don’t have many rights on the servers at work, so it took me and my collegue a bit of time to conclude that we were trying to run Nicks code on a .NET 2.0 base – and that didn’t work out, of course.

I already have a few ColdFusion pages with diagnostics about our servers, so I decided to do the right thing and add the .NET version to the existing diagnostics. It took me a while to find the exact class and method in the .NET runtime, but it turned out to be simple. So I have created a small ColdFusion CFC to help me (the » symbol means you should put what follows on the preceding line):

<cfcomponent
   name="DotnetRuntime" >

   <cfset VARIABLES.re = CreateObject( "dotnet",
             » "System.Runtime.InteropServices.RuntimeEnvironment" ) />

   <cffunction
      name="GetRuntimeDirectory"
      access="public"
      returntype="string"
      output="false" >

      <cfreturn VARIABLES.re.GetRuntimeDirectory() />

   </cffunction>

   <cffunction
      name="GetSystemVersion"
      access="public"
      returntype="string"
      output="false" >

      <cfreturn VARIABLES.re.GetSystemVersion() />

   </cffunction>

</cfcomponent>

Once you have that component, it’s pretty simple to use it – just put this in a .CFM (I’m supposing you have called your CFC ‘DotnetRuntime.cfc‘ in the current directory):

<cfsilent>
    <cfset dotnet = CreateObject( "component", "DotnetRuntime" ) />
</cfsilent>

<cfoutput>
   <html>
   <body>
      <h1>Dotnet Runtime Environment</h1>

      <p>
         This ColdFusion server is currently running <b>.NET version #dotnet.GetsystemVersion()#</b>
         from directory '<code>#dotnet.GetRuntimeDirectory()#</code>'
      </p>
   </body>
   </html>
</cfoutput>

So there you have it. I know this works in our setup, but I don’t know what will happen when there are multiple .NET runtimes on your machine… That’s why I wrapped the code into a CFC –  functions to detect specific versions of .NET, handle multiple runtimes, etc. can thus be added in a single component for easy versioning and maximum reuse. Suggestions or additions are welcome!

PS. I have left the “hint” attributes out of the code above, because I haven’t yet found a good way to publish program code in WordPress.

Read Full Post »