1

Using New Atlanta's BlueDragon.NET implementation of ColdFusion, we have the ability to create instances of C# .NET objects using the cold fusion tag. For example:

<cfobject name="list" type=".net" action="CREATE"
 class="System.Collections.ArrayList">

In one case, however, we need to create an instance of a generic type. This works for internal types like System.Int32:

<cfobject name="list" type=".net" action="CREATE"
 class="System.Collections.Generic.List`1[[System.Int32]]">

But, when using our own assembly-qualified class, like the following:

namespace Foo.Bar.Bam
{
    public class MyClassName
}

that is compiled to the assembly Foo.Bar.dll and used like so:

<cfobject name="list" type=".net" action="CREATE"
 class="System.Collections.Generic.List`1[[Foo.Bar.Bam.MyClassName,Foo.Bar]]">

it fails with an "BlueDragon Internal Server Error" with the following stack trace:

java.lang.ClassNotFoundException: Could not load file or assembly 'Foo.Bar]]' or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.AppDomain.Load(String assemblyString)
   at com.nary.util.ClassUtils.forName(String className)
   at com.naryx.tagfusion.cfm.tag.cfOBJECT.render(cfSession session)
   at com.naryx.tagfusion.cfm.tag.cfTag.coreRender(cfSession _Session)
   at com.naryx.tagfusion.cfm.engine.cfSession.onRequest(cfFile requestFile)
   at com.naryx.tagfusion.cfm.engine.cfEngine.service(cfSession _Session)

Without the assembly qualification, it fails with a CFML error:

Failed to load class, System.Collections.Generic.List`1[[Foo.Bar.Bam.MyClassName]]

Is there any way to create an instance of a generic type using ?

Shog9
  • 156,901
  • 35
  • 231
  • 235
iammichael
  • 9,477
  • 3
  • 32
  • 42

1 Answers1

0

You must specify the name of your Assembly (dll) not the keyword Assembly.

Given:

namespace Me
{
   public class Foo { }
}

and compiling to MyStuff.Dll; the class would be

class="System.Collections.Generic.List`1[[Me.Foo, MyStuff]]">
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
  • edited question to clarify ("Assembly" was just a sample assembly name and not any reference to a keyword "Assembly" or the System.Reflection.Assembly class) – iammichael Jun 06 '11 at 16:41