3
votes

I'm a junior C# developer and I'm trying to learn Web Development with ColdFusion. I'm having difficulty running this example in the documentation: Using a .NET class directly. This is just a simple cfm code to test .NET function on ColdFusion.

<cffunction name="Ping" returntype="string" output="false"> 
    <cfargument name="host" type="string" required="yes"> 
    <!--- Local variables ---> 
    <cfset var pingClass=""> 
    <cfset var pingReply=""> 
    <!--- Get Ping class ---> 
    <cfobject type=".NET" name="pingClass" 
            class="System.Net.NetworkInformation.Ping"> 
    <!--- Perform synchronous ping (using defaults) --->  
    <cfset pingReply=pingClass.Send(Arguments.host)> 
    <!--- Return result ---> 
    <cfreturn pingReply.Get_Status().ToString()> 
</cffunction> 

I installed ColdFusion 2016 with these settings: Server Configuration, Production Profile + Secure Profile with IP address 127.0.0.1, .NET integration Service, and Built-in web server.

I placed the CFM code here C:\ColdFusion2016\cfusion\wwwroot\test.cfm and I ran it through the browser like this http://127.0.0.1:8500/test.cfm. The error that I get from jnbridge log is "Class Not Found". I have .NET framework installed and the ColdFusion .NET service is running. I also tried restarting everything but it still won't work. Please help. Thank you.

2
Tip: You may want to take a look at cfscript. As of CF11+, just about anything you can do with CFML ie tags, is also supported in cfscript. The syntax is very similar to java / C#, so you may find it more natural coming from C#. - Leigh

2 Answers

4
votes

Class System.Net.NetworkInformation.Ping not found in the specified assembly list.

The assembly that contains the class must be provided to the assembly attribute.

https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-m-o/cfobject-net-object.html

http://cfdocs.org/cfobject

This seems to work:

<cfobject type="dotnet" name="pingClass"
    assembly="C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll"
    class="System.Net.NetworkInformation.Ping">

You can also use createObject() instead of <cfobject>. http://cfdocs.org/createobject

0
votes

So my coworker figured it out how to run the code in CF. Here are the steps from the beginning

  1. Install CF Server
  2. Install CF Builder without creating another server
  3. On the builder, add CF server by clicking + button somewhere
  4. Type the name 'coldfusion' not coldfusion2016' or 'coldfusion10'. Just 'coldfusion'.
  5. Run the cfm through CFBuilder