Results 1 to 3 of 3

Thread: Error creating a proxy-Help!

  1. #1
    Join Date
    Dec 2007
    Posts
    2

    Default Error creating a proxy-Help!

    I wanted to get started with AOP, so simplified Spring.AopQuickStart.Step1 sample to fit into simple VS.NET 2005 project.
    I get following error "Unable to cast object of type 'CompositionAopProxy_6839ee888b5144eb86aa6df347e48 e21' to type 'ICommand'" while creating proxy.

    Following is the code and web.config.Any help is appreciated. Thanks

    class Program
    {
    static void Main(string[] args)
    {
    IApplicationContext ctx = ContextRegistry.GetContext();
    //Get error here on line below
    ICommand command = (ICommand)(ctx["myServiceCommand"]);

    command.Execute();
    }
    }
    interface ICommand
    {
    bool IsUndoCapable { get; }
    void Execute();
    void UnExecute();
    }
    class ServiceCommand : ICommand
    {
    bool ICommand.IsUndoCapable
    {get { return true; }}
    void ICommand.Execute() {}
    void ICommand.UnExecute() {}
    }

    config file below:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <sectionGroup name="spring">
    <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
    <section name="objects" type="Spring.Context.Support.DefaultSectionHandler , Spring.Core" />
    </sectionGroup>
    </configSections>
    <spring>
    <context>
    <resource uri="config://spring/objects" />
    </context>
    <objects xmlns="http://www.springframework.net">
    <description>An example that demonstrates simple AOP functionality.</description>
    <object id="myServiceCommand" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
    <property name="Target">
    <object type="ServiceCommand, SprintNetAOP" />
    </property>
    </object>
    </objects>
    </spring>
    </configuration>

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Cambridge, UK
    Posts
    1,340

    Default

    Hi,

    In short: making ICommand public should solve your pb.

    Your is most likely caused by the ICommand interface not being public. Due to being internal, the dynamically generated proxy class can't implement the interface.

    -Erich

  3. #3
    Join Date
    Dec 2007
    Posts
    2

    Default Thanks

    Yes! Thanks. That was it.

Posting Permissions

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