1 Reply Latest reply on May 15, 2008 6:06 AM by bulldog65

    Trouble passing a .net object into a .net function

    fuxuepeng
      Summary: I'm creating a .net object (System.Reflection.BindingFlags) into a function that takes that argument. However, when I pass that in, CF can't find the correct function. If I pass a null value, CF finds it just fine, but because the function really does need a BindingFlags object to work, the function causing an exception.

      Details: I'm attempting to get the IPSecurity settings from an IIS entry. In .Net this is done by grabbing the appropriate IIS object, then getting the "value" of the IPSecurity property. That value is actually an object. I then get the "Type" for that object and can manipulate it using the InvokeMember method associated with "Type" objects. The second parameter it requires is a BindingFlags object. In .net bindingFlags isn't actually an object in the traditional sense, it's an enum (more like a struct) and when I use it properly (BindingFlags.GetProperty) it actually passes an INT. I think part of my problem is that BindingFlags is actually a struct that is getting special treatment from CF (adding a wrapper).

      What I'd like: In a perfect world I'd like someone to say: Here is the solution . . .. However, I'd settle for a good way to find out what type of object CF thinks its getting (BTW, I've done a CF dump on my object and it has the correct class).

      The code:
      <cfobject type=".NET" name="entry" class="System.DirectoryServices.DirectoryEntry" assembly="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll" />
      <cfset entry.init("IIS://dev03/w3svc/1/root/planitax/testMe")/>
      <cfobject type=".NET" name="BindingFlags" class="System.Reflection.BindingFlags" />
      <cfset BindingFlags.init() />
      <cfset params = ["IPSecurity"] />
      <cfset comObj = entry.Invoke("Get", params) />
      <cfset comType = comObj.GetType() />
      <cfset object = comType.InvokeMember("IPDeny", BindingFlags.GetProperty, javacast("null",""), comObj, javacast("null","")) />

      Error:

      The InvokeMember method was not found.
      Either there are no methods with the specified method name and argument types, or the InvokeMember method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.

      Trace:

      coldfusion.runtime.java.MethodSelectionException: The InvokeMember method was not found.
      at coldfusion.runtime.java.ObjectHandler.findMethodUsingCFMLRules(ObjectHandler.java:307)
      at coldfusion.runtime.StructBean.invoke(StructBean.java:514)
      at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2291)
      at cftest2ecfm659646706.runPage(D:\Documents and Settings\rex.m.phillips\workspace\IISModifier\test.cfm:16)
      at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:192)
      at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:366)
      at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
      at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
      at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
      at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
      at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
      at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
      at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
      at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
      at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:2 8)
      at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
      at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
      at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
      at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
      at coldfusion.CfmServlet.service(CfmServlet.java:175)
      at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
      at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
      at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42 )
      at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
      at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
      at jrun.servlet.FilterChain.service(FilterChain.java:101)
      at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
      at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
      at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:284)
      at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
      at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
      at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
      at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
      at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
      at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

      BTW, if I use a NULL value instead, I get following (note that it shows how to use the function):

      System.ArgumentException: Must specify binding flags describing the invoke operation required (BindingFlags.InvokeMethod CreateInstance GetField SetField GetProperty SetProperty).
      Parameter name: bindingFlags
      at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
      at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java: 39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorIm pl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at com.jnbridge.jnbcore.DotNetObjectBase.a(Unknown Source)
      at com.jnbridge.jnbcore.ExceptionFactory.throwException(Unknown Source)
      at System.Type.InvokeMember()
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at coldfusion.runtime.StructBean.invoke(StructBean.java:498)
      at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2291)
      at cftest2ecfm659646706.runPage(D:\Documents and Settings\rex.m.phillips\workspace\IISModifier\test.cfm:15)
      at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:192)
      at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:366)
      at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
      at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
      at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
      at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
      at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
      at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
      at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
      at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
      at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:2 8)
      at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
      at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
      at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
      at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
      at coldfusion.CfmServlet.service(CfmServlet.java:175)
      at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
      at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
      at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42 )
      at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
      at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
      at jrun.servlet.FilterChain.service(FilterChain.java:101)
      at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
      at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
      at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:284)
      at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
      at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
      at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
      at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
      at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
      at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
        • 1. Re: Trouble passing a .net object into a .net function
          bulldog65
          I was just wondering if you found a solution to your issue. I am having the same problem. I am attempting to create a new IIS website through Coldfusion using the .Net System.DirectoryServices.DirectoryEntry class. When I try to the Invoke method, the second parameter is System.Object and I and getting a ystem.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) error. So my problem is finding a way to create the System.Object parameter to paa into the Invoke method.