我正在使用我无法调整的自定义 .NET DLL 进行一些 ColdFusion 10 集成。IEnumerable
在此过程中,除了创建数据类型以传递给对象的方法之一之外,我已经能够做所有我需要做的事情。这是我需要与之集成的内容:
这是Set_Events
我遇到麻烦的方法。我可以创建应该是该枚举变量一部分的单个事件,但我无法创建它显然期望的正确变量类型。我试过这样做:
<cfset enum = createObject(".net", "System.Collections.Generic.IEnumerable__1") />
这给了我一个有效的 .NET 对象,它有一个GetEnumerator()
方法:
当我尝试调用该方法时:
<cfdump var="#enum.GetEnumerator()#">
这只是给了我以下错误:
The GetEnumerator method was not found.
我尝试过的其他事情:
创建通用列表并添加内容:
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar") />
<cfset eventList.Add(javacast("bigdecimal", "30.1234" )) />
这给了我以下错误:
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : System.Collections.Generic.List__1
这又给了我同样的错误:
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar") />
<cfset eventList.Add("foo") />
尝试初始化列表
Leigh 的这段代码有效:
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar") />
<cfset elemClass = createObject(".net", "System.String", "dotNetCoreProxy.jar") />
<cfset elemType = elemClass.getDotNetClass() />
<cfset eventList.init( elemType ) />
<cfset eventList.Add("foo") />
<cfdump var="#eventList#">
但这不会:
<cfobject type="dotnet" name="VideoWallEvent" class="Utilities.VideoWall.VideoWallEvent" assembly="#ExpandPath("Utilities.dll")#">
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", "dotNetCoreProxy.jar") />
<cfset elemType = VideoWallEvent.getDotNetClass() />
<cfset eventList.init( elemType ) />
<cfdump var="#eventList#">
我收到以下错误:
Unable to find a constructor for class System.Collections.Generic.List__1 that accepts parameters of type ( System.RuntimeType ).
JNBProxyGUI.exe
这已经完全没用了。我可以浏览到我的 Utilities.dll 文件,并从 GAC 添加 System.Collections 程序集,但“项目”菜单中的“构建”选项始终处于禁用状态,一旦添加了这些程序集,任何窗格中都不会显示任何内容。
测试方法
我在一页上运行了以下所有代码:
<cfset UtilitiesProxy = ExpandPath("UtilitiesProxy.jar") />
<cfset DotNetCoreProxy = "dotNetCoreProxy.jar" />
<cfset CoStarUtilities = ExpandPath("CoStar.Utilities.dll") />
<h2>Try using base DLLs and DotNetCore</h2>
<cftry>
<cfobject type="dotnet" name="VideoWallEvent" class="CoStar.Utilities.VideoWall.VideoWallEvent" assembly="#CoStarUtilities#">
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", DotNetCoreProxy) />
<cfdump var="#eventList.init(VideoWallEvent.getDotNetClass())#"> (error line)
<cfcatch>
<h3><cfoutput>#cfcatch.type#</cfoutput></h3>
<p><cfoutput>#cfcatch.message#: #cfcatch.detail#</cfoutput></p>
</cfcatch>
</cftry>
<h2>Try using the Utilities Proxy for Everything</h2>
<cftry>
<cfobject type="dotnet" name="VideoWallEvent" class="CoStar.Utilities.VideoWall.VideoWallEvent" assembly="#UtilitiesProxy#">
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", UtilitiesProxy) /> (error line)
<cfdump var="#eventList.init(VideoWallEvent.getDotNetClass())#">
<cfcatch>
<h3><cfoutput>#cfcatch.type#</cfoutput></h3>
<p><cfoutput>#cfcatch.message#: #cfcatch.detail#</cfoutput></p>
</cfcatch>
</cftry>
<h2>Try using Utilities Proxy for VideoWall, and DotNetCore for List</h2>
<cftry>
<cfobject type="dotnet" name="VideoWallEvent" class="CoStar.Utilities.VideoWall.VideoWallEvent" assembly="#UtilitiesProxy#">
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", DotNetCoreProxy) />
<cfdump var="#eventList.init(VideoWallEvent.getDotNetClass())#"> (error line)
<cfcatch>
<h3><cfoutput>#cfcatch.type#</cfoutput></h3>
<p><cfoutput>#cfcatch.message#: #cfcatch.detail#</cfoutput></p>
</cfcatch>
</cftry>
<h2>Try Initing Wall Event</h2>
<cftry>
<cfobject type="dotnet" name="VideoWallEvent" class="CoStar.Utilities.VideoWall.VideoWallEvent" assembly="#CoStarUtilities#">
<cfset VideoWallEvent.Init() />
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", DotNetCoreProxy) />
<cfdump var="#eventList.init(VideoWallEvent.getDotNetClass())#"> (error line)
<cfcatch>
<h3><cfoutput>#cfcatch.type#</cfoutput></h3>
<p><cfoutput>#cfcatch.message#: #cfcatch.detail#</cfoutput></p>
</cfcatch>
</cftry>
<h2>Try Initing Wall Event</h2>
<cftry>
<cfobject type="dotnet" name="VideoWallEvent" class="CoStar.Utilities.VideoWall.VideoWallEvent" assembly="#CoStarUtilities#">
<cfset VideoWallEvent.Init() />
<cfset eventList = CreateObject(".net","System.Collections.Generic.List`1", DotNetCoreProxy) />
<cfdump var="#eventList.init(VideoWallEvent)#"> (error line)
<cfcatch>
<h3><cfoutput>#cfcatch.type#</cfoutput></h3>
<p><cfoutput>#cfcatch.message#: #cfcatch.detail#</cfoutput></p>
</cfcatch>
</cftry>
我得到以下错误输出(提示,每一个都失败了)。
09:22:45.045 - Object Exception - in C:/inetpub/LandsofAmerica/scribble/VideoWall/index.cfm : line 9
Unable to find a constructor for class System.Collections.Generic.List__1 that accepts parameters of type ( System.RuntimeType ).
09:22:48.048 - coldfusion.runtime.dotnet.ProxyGenerationException - in C:/inetpub/LandsofAmerica/scribble/VideoWall/index.cfm : line 19
09:22:48.048 - Object Exception - in C:/inetpub/LandsofAmerica/scribble/VideoWall/index.cfm : line 31
Unable to find a constructor for class System.Collections.Generic.List__1 that accepts parameters of type ( System.RuntimeType ).
09:22:48.048 - Object Exception - in C:/inetpub/LandsofAmerica/scribble/VideoWall/index.cfm : line 43
Unable to find a constructor for class System.Collections.Generic.List__1 that accepts parameters of type ( System.RuntimeType ).
09:22:48.048 - Object Exception - in C:/inetpub/LandsofAmerica/scribble/VideoWall/index.cfm : line 55
Unable to find a constructor for class System.Collections.Generic.List__1 that accepts parameters of type ( CoStar.Utilities.VideoWall.VideoWallEvent ).
我已经用(我认为是)我需要的所有项目生成了一个代理。
结论
所以现在我被困住了。我可以实例化并填充所有必要的对象以使这个东西工作,我只是不能将所有对象推到一起以使它们工作。尝试创建填充 Set_Events 方法所需的 ENum 对象时,我缺少什么?