Hi Krzysztof,

 

The problem is that this is part of a bigger application, using a custom
application framework built on top of Castle Windsor… so it’s not very
isolated. Even more puzzling, the Typed Factory works correctly most of the
time in other applications; it’s only in this specific application that
we’re seeing this.

 

I did some further research: if I try to use the Typed Factory
(IEntityFactory) at another place within the same application (even in the
same assembly), it works flawlessly – which is very strange. So, the result
is this:

 

1)      If I use the IEntityFactory from my PoFromWoModule, it works
flawlessly – no exception. The PoFromWoModule is registered using
“windsorContainer.Register(Component.For(type))” syntax, i.e. very “plain”
registration.

2)      If I use the IEntityFactory from my RowsViewModel, it doesn’t work
– I get the “type constraint violation” exception. The RowsViewModel is
registered in a much more complex fashion, like this:
“windsorContainer.Register(AllTypes.FromAssembly(assembly).Where((t) =>
t.IsSubclassOf(typeof(ViewModelBase))).Configure(c =>
c.LifeStyle.Singleton.Interceptors(typeof(IPropertySetInterceptor))));”. As
you see, the main difference between these two components (PoFromWoModule
and RowsViewModel) is that the latter uses interception.

3)      Even stranger: If I let both these components (PoFromWoModule and
RowsViewModel) receive an IEntityFactory using property-injection, it
works! It even works without the PoFromWoModule actually using the
IEntityFactory; just receiving it from the property-based DI seems to make
a difference somehow…

 

I wish I could send you an isolated test case, but it isn’t that
straightforward unfortunately. If you like, however, I could possibly show
you the code using Skype sharing or something like that. Would that be an
option?

 

Best regards,

Per

 

From: [email protected]
[mailto:[email protected]] On Behalf Of Krzysztof
Kozmic
Sent: den 20 januari 2011 14:35
To: [email protected]
Subject: Re: Strange constraint violation problem with typed factories in
Castle Windsor 2.5.1

 

Please submit a failing test case. Otherwise we'd be guessing.

On 20/01/2011 9:32 PM, Lundberg, Per wrote: 

Hello,

We are using the Typed Factory facility in our application framework, to
provide an easy way to be able to instantiate transient components (view
models and entities, in our case).

This has worked well for some time now. However, recently, a very weird
issue has popped up: in one of our project (not all of them), the factory
that we are using is throwing an exception whose message looks like this:

GenericArguments[0], 'T', on
'Castle.Proxies.Invocations.IEntityFactory_CreateEntity[T]' violates the
constraint of type parameter 'T'.

The source of the exception is the DynamicProxyGenAssembly2. The class
causing the exception is
Castle.Proxies.IEntityFactoryProxy.CreateEntity[T]() our factory interface
is IEntityFactory, and the relevant method is defined like this:

T CreateEntity<T>() where T : EntityBase;

The strange is that the T type that we are passing in to the method clearly
derives from EntityBase (obviously in a correct manner, because otherwise
the compiler would yell at us)

Any suggestions/ideas? As mentioned above, we are still on Castle Windsor
2.5.1.

Best regards,

Per Lundberg

-- 
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.

 

-- 
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to