Domanda

I'm working on an application that uses Spring AOP extensively. The application was written in .NET 2.0, but I'm trying to upgrade it to .NET 4.0. This has meant an upgrade from Spring 1.2.0 to 1.3.2, however, this appears to have caused some issues.

This is the error I now receive when trying to access the default page.

Error thrown by a dependency of object 'IType1' defined in 'file [C:\svn\Application.Web\Configs\ImmutableDefinitions.xml] line 55' : Unsatisfied dependency expressed through constructor argument with index 0 of type [Application.Logic.Process.OrderBlo] : Error thrown by a dependency of object 'OrderBlo' defined in 'file [C:\svn\Application.Web\Configs\Order_Logic.xml] line 10' : Initialization of object failed : Cannot instantiate Type [Application.Interceptors.ActivityMonitorInterceptor] using ctor [Void .ctor(Application.Logic.ActivityMonitorBlo)] : 'Unable to cast object of type 'CompositionAopProxy_fe703921758d417f8e6a2d4a6b9ff525' to type 'Application.Logic.ActivityMonitorBlo'.'while resolving 'organisationBlo' to 'OrganisationBlo' defined in 'file ... Followed by cascading type initializers...

Now to be clear, this worked perfectly fine in .NET 2.0 with Spring 1.2.0. So the question is, what changed between 1.2.0 and 1.3.2 that could cause this error? Alternatively, can someone explain this error further, and how aop could cause this?

I've not upgraded any other libraries in the solution other than Spring.Core, Spring.Aop and all other Spring.* references.

È stato utile?

Soluzione

I'm not sure about the change history between 1.2.0 and 1.3.2, but the error message tells me that you are trying to set inject a Application.Logic.ActivityMonitorBlo property or constructor argument with an advised dependency.

When you define an advice for a target object, spring.net by default creates a composition based proxy, proxying all interfaces it finds on the target's class. If it doesn't find any interfaces, then it creates a proxy class that inherits the target class and creates proxy methods for all virtual methods on the target's class, see the spring docs on proxying mechanisms.

I've gotten this error message on numerous occasions, for instance when I added an interface to a class that previously didn't have any interfaces. Suddenly the aop proxy no longer was of the target type's class, but a composition based proxy implementing only the added interface, resulting in the same error.

(Note that it is generally best to depend on interfaces instead of concrete classes.)

Something that did change somewhere between 1.1.0 and 1.3.2 was the addition of an inheritance based aop configurer, but I'm not really sure how that would relate to your question.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top