Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UseCoravelPro() error #8

Closed
XardasLord opened this issue Jul 20, 2019 · 10 comments
Closed

UseCoravelPro() error #8

XardasLord opened this issue Jul 20, 2019 · 10 comments
Assignees

Comments

@XardasLord
Copy link

XardasLord commented Jul 20, 2019

I have an error at this line: app.UseCoravelPro(). The error says:

System.InvalidOperationException: 'No service for type 'GP.SS.Database.SaldeoSynchronizatorContext' has been registered.'

But according to the documentation I have registered it:

services.AddDbContext<ISaldeoSynchronizatorContext, SaldeoSynchronizatorContext>( opts => opts.UseOracle(Configuration.GetConnectionString("SaldeoSynchronizatorDB"), b => b.MigrationsAssembly(typeof(ISaldeoSynchronizatorContext).Namespace)) );

services.AddCoravelPro(typeof(SaldeoSynchronizatorContext));
@jamesmh
Copy link
Owner

jamesmh commented Jul 20, 2019

Try services.AddCoravelPro(typeof(ISaldeoSynchronizatorContext)); - although I'm not totally sure if that would work.

@jamesmh
Copy link
Owner

jamesmh commented Jul 20, 2019

The issue is that whatever type you pass to AddCoravelPro has to be registered as the actual type in the service container vs. a resolved type. Let me know 👍

@jamesmh jamesmh self-assigned this Jul 20, 2019
@XardasLord
Copy link
Author

XardasLord commented Jul 20, 2019

@jamesmh Thanks for your very fast answer :)

I tried it services.AddCoravelPro(typeof(ISaldeoSynchronizatorContext)) earlier and got this message:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

But I also tried to register DbContext like following (without interface):

services.AddDbContext<SaldeoSynchronizatorContext>(
                opts => opts.UseOracle(Configuration.GetConnectionString("SaldeoSynchronizatorDB"),
                    b => b.MigrationsAssembly(typeof(SaldeoSynchronizatorContext).Namespace))
            );

But then I got this error message:

System.InvalidOperationException: 'Unable to resolve service for type 'GP.SS.Database.ISaldeoSynchronizatorContext' while attempting to activate 'GP.SS.Business.SynchronizationService'.'

@jamesmh
Copy link
Owner

jamesmh commented Jul 20, 2019

Did you try this combination?

services.AddDbContext<SaldeoSynchronizatorContext>(
                opts => opts.UseOracle(Configuration.GetConnectionString("SaldeoSynchronizatorDB"),
                    b => b.MigrationsAssembly(typeof(SaldeoSynchronizatorContext).Namespace))
            );

services.AddCoravelPro(typeof(SaldeoSynchronizatorContext));

@XardasLord
Copy link
Author

XardasLord commented Jul 20, 2019

Yes, then I got this error:

System.InvalidOperationException: 'Unable to resolve service for type 'GP.SS.Database.ISaldeoSynchronizatorContext' while attempting to activate 'GP.SS.Business.SynchronizationService'.'

EDIT: @jamesmh Wait, but this error is because I inject the dbcontext interface in another service... Hmm but isn't your library prepared for the injectable dbcontext?

@XardasLord
Copy link
Author

@jamesmh
I removed interface for DbContext and replaced it just to inject the dbContext class in other services.
Now I have this error:

System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load file or assembly 'System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

@XardasLord
Copy link
Author

I solved the problem by adding nuget package System.DirectoryServices.Protocols. There is nothing in a documentation about it - maybe you can add some info about it? :)

@jamesmh
Copy link
Owner

jamesmh commented Jul 20, 2019

That doesn't sound like an issue with Coravel Pro, but looks like some other transient dependencies that was missing.

What version of .NET Core are you using?

@XardasLord
Copy link
Author

I'm using .NET Core 2.2

@jamesmh
Copy link
Owner

jamesmh commented Jul 21, 2019

K. Coravel Pro has no dependency on DirectoryServices. Sounds like the either the Oracle provider or potentially something else in perhaps another project (maybe?) has a transitive dependency on that package - for some reason.

I'll close this this now 👍 Glad you figure it out 😊

@jamesmh jamesmh closed this as completed Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants