External data

Topics: Writing modules
Jun 13, 2011 at 11:37 AM

I'm trying to use an service class within an external dll. The Interface of the service inherits from IDependency

Unfortunaly i get the following error when using the service:

None of the constructors found with policy 'Orchard.Environment.AutofacUtil.DynamicProxy2.ConstructorFinderWrapper' on type '.......' can be invoked with the available services and parameters:

Constructor 'Void .ctor(.....IPlayerService, ..IPlayerService, Orchard.IWorkContextAccessor)' parameter resolution failed at parameter '....Abstraction.IPlayerService playerService1'.

Thanks!

Developer
Jun 13, 2011 at 2:43 PM

This error happens when implementations of some interfaces referenced in the constructor (IPlayerService in your case) are not registered within the IoC container. Orchard just cannot "see" them.

Check if the IPlayerService has an implementation that is publicly visible (must be "public"). If it is public, then there's something with harvesting implementations of IDepndency from custom dlls. I'm not sure if Orchard harvests implementations from custom assemblies at all - have to check that.

If I were you, I'd create an empty class derived from your IPlayerService implementation inside your module, eg. public class PlayerService2 : MyPlayerService {<nothing here>} and see if it helps.

Jun 13, 2011 at 3:08 PM
Edited Jun 13, 2011 at 3:08 PM

I think the problem here is with Orchard finding IDependency iheritors in an external DLL. Are you saying that IPlayerService inherites from IDependency but lives in this external DLL? The way dependency injection is set up, it only looks in Orchard modules themselves. I saw a thread previously about this. You might have to mess around with the IoC container at a slightly lower level to get that setup working. You're better off either implementing your service as an Orchard module, or exposing an interface from it which you can then provider an IDependency wrapper for in your actual module.

Developer
Jun 13, 2011 at 3:22 PM

@Pete: You're right. I checked that and Orchard isn't checking custom assemblies for IDependency implementations.

I guess the quickest options would be the one I stated above - create an implementation directly in the module so that Orchard will catch it. That implementation is already implementing a service interface decorated with IDependency. So simply making it visible by overriding it inside a module should make everything work.

Jun 13, 2011 at 6:56 PM

Ok i moved the service implementation to the module but now i'm getting the following error:

Attempt by security transparent method '....PlayerService.GetAllPlayers()' to access security critical method '....SportsTeamContext..ctor()' failed.

Seems like i can't access methods from other dlls from the module service implementation? Any suggestions?
 
Coordinator
Jun 13, 2011 at 7:07 PM

Are you running in medium trust? Can you try with full trust? It looks like your dll is doing stuff that is not allowed under the current trust level. I could be wrong.

Jun 13, 2011 at 7:47 PM

i allready tried that but unfortunaly it didn't help.

Developer
Jun 13, 2011 at 8:00 PM

Had it before - code running in partially trusted environment cannot call external libraries. First - set your app to run in Full Trust mode and next, try marking your custom assembly with [assembly: AllowPartiallyTrustedCallers] attribute (in AssemblyInfo.cs file). In order to be able to use that library it must be strongly named.

There is also a nice article describing the usage of libraries from partially trusted code.

Developer
Jun 13, 2011 at 8:04 PM

I've also noticed that Orchard assemblies use the SecurityTransparent attribute. You can try setting that in your AssemblyInfo.cs file ([assembly: SecurityTransparent]). Assemblies marked with that can be accessed from partially-trusted code.


Jun 15, 2011 at 7:13 PM

Thanks guys! It's working now with the attributes:

[assembly: SecurityTransparent] and [assembly: AllowPartiallyTrustedCallers]

So Fixed!

Developer
Jun 15, 2011 at 7:25 PM

Glad you made it work!

Oct 5, 2011 at 11:45 AM
Znowman wrote:

Thanks guys! It's working now with the attributes:

[assembly: SecurityTransparent] and [assembly: AllowPartiallyTrustedCallers]

So Fixed!

Znowman, could you please specify in which dll you used these assembly attributes? Was it the external one, or did you alter an orchard core project?