Results 1 to 3 of 3

Thread: Autoproxy invalid cast

  1. #1
    Join Date
    Jul 2007
    Posts
    54

    Default Autoproxy invalid cast

    I am applying DebugInterceptor example to learn more about the autoproxy feature.

    I have been able to successfully apply the DebugInterceptor using the ProxyFactory in code. Now I want to try and do it with an autoproxy configuration.

    It seems easy enough but I get an invalid cast exception.

    Any advice?

    Thanks,
    jeff

    System.InvalidCastException: Unable to cast object of type 'CompositionAopProxy_34cf5a029be14c439e4d8755fb96c 726' to type 'PW3Info.baseelement.data.BaseElement'.


    Code:
    BaseElement myBaseElement = (BaseElement) Globals.Factory.GetObject("myBaseElement");
    Code:
      <object name="myBaseElement"
               type="PW3Info.baseelement.data.BaseElement, PW3Info">
        <property name="ElementName" value="StoreID" />
        <property name="Description" value="The Store Identifier" />
      </object>
    
      <object id="debugInterceptor" type="PW3Info.aop.DebugInterceptor, PW3Info">
      </object>
    
      <object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
        <property name="ObjectNames">
          <list>
            <value>myBaseElement</value>
          </list>
        </property>
        <property name="InterceptorNames">
          <list>
            <value>debugInterceptor</value>
          </list>
        </property>
      </object>

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    With default configuration, CompositionAopProxy is used and require that your target implements an interface to be implemented by the proxy, so you can't cast it to a class.
    Quote Originally Posted by jjarrel View Post
    Code:
    BaseElement myBaseElement = (BaseElement) Globals.Factory.GetObject("myBaseElement");
    There is another option setting ProxyTargetType="true", you will be able to proxy the target type but only methods marked as virtual will be proxied.
    Code:
    <object id="ProxyCreator" type="Spring.Aop.Framework.AutoProxy.ObjectNameAutoProxyCreator, Spring.Aop">
       <property name="ProxyTargetType" value="true"/>
       <property name="ObjectNames">
          <list>
            <value>myBaseElement</value>
          </list>
       </property>
       <property name="InterceptorNames">
          <list>
            <value>debugInterceptor</value>
          </list>
       </property>
    </object>

    Reference documentation :
    12.5.3. Proxying Interfaces
    12.5.4. Proxying Classes


    HTH,
    Bruno
    My english is as poor as my taylor is rich

  3. #3
    Join Date
    Jul 2007
    Posts
    54

    Default

    Great. Thanks for the clarification. I think I get it at this point.

    jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •