builder.Services.AddDbContext<AppDbContext>(x =>
{
x.UseSqlServer(builder.Configuration.GetConnectionString("SqlConnection"), option =>
{
option.MigrationsAssembly(Assembly.GetAssembly(typeof(AppDbContext)).GetName().Name);
});
});
System.InvalidOperationException: 'Cannot modify ServiceCollection after application is built.'
When I run the program I get the above error.
However, when trying to migrate, I get the following error
Unable to create an object of type 'AppDbContext'.
It looks like your adding this after builder.Build() has been called, difficult to see without the full code.
Can you try moving it before?
Related
I am very new to Graphql and trying to implement mutations in dotnet using nreco.graphql, as of now there are no errors in the project files , when I tried to execute the mutation query am getting below error message. It says the input format what we are passing is not valid but I verified it many times and there is no error in it. So please help me to resolve the issue.
Query:
mutation($TestValue:TestInput!) {
ActivateInactivateUser(data:$TestValue) {
Status
}
}
Query Variables:
{
"TestValue": {
"UserID": "5",
"UserName": "Test",
"Status": "Inactive"
}
}
Error message:
Variable '$TestValue' is invalid. Unable to parse input as a 'TestInput' type. Did you provide a List or Scalar value accidentally
I am very new to Graphql and trying to implement mutations in dotnet using nreco.graphql, as of now there are no errors in the project file
As far as I know, NReco.GraphQL based on engine Graph.Net. When it comes to mutation queries - you can check the docs from Graph.Net team here
Error message: Variable '$TestValue' is invalid. Unable to parse input as a 'TestInput' type. Did you provide a List or Scalar value accidentally
Did you set up an appropriate model for the method "ActivateInactivateUser"?
You ought to add sth like this:
public class TestInputType : InputObjectGraphType
I'm attempting to integrate GrapQL.EntityFramework using a DB first approach on an Azure Function. I've generated the needed contexts, User graphs, query, along with the function itself. Currently I'm having an issue with the Startup file of my function app where I am to use dependency injection.
I've attempted both options on the configuration guide in the GraphQL.EntityFramework Docs. I've also made attempts at snippets of code such as builder.Services.AddSingleton(typeof(IEfGraphQLService<PersonarDBContext>),instance => { return new DBContext(); });
The current state of my startup file
public override void Configure(IFunctionsHostBuilder builder)
{
string connection = ""
builder.Services.AddTransient<UserQuery>();
builder.Services.AddDbContext<DBContext>(options => options.UseSqlServer(connection));
var optionBuilder = new DbContextOptionsBuilder<DBContext>();
optionBuilder.UseSqlServer(connection);
EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);
builder.Services.AddSingleton(typeof(IEfGraphQLService<DBContext>),instance => { return new DBContext(); });
}
At this point in time I am just attempting to get my function app to startup properly. I am currently experiencing this error output.
User: Microsoft.Azure.WebJobs.Host: Error indexing method 'User'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'service' to type IEfGraphQLService`1. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
Likely worth opening an issue on GitHub but my suspicion is whatever the library is trying to auto-register here is throwing the exception
EfGraphQLConventions.RegisterInContainer<DBContext>(builder.Services, null);
EfGraphQLConventions.RegisterConnectionTypesInContainer(builder.Services);
I cant figure out why I am getting this error below within the RegisterCollection method. Am I doing the setup incorrectly?
The container can't be changed after the first call to GetInstance, GetAllInstances, Verify, and some calls of GetRegistration. Please see https://simpleinjector.org/locked to understand why the container is locked. The following stack trace describes the location where the container was locked:
Logger registration
public static void Register(Container container)
{
container.RegisterConditional(typeof(ILogger),
c => typeof(NLogLogger<>).MakeGenericType(
c.Consumer?.ImplementationType ?? typeof(object)),
Lifestyle.Transient,
c => true);
...
}
container.RegisterCollection throws the error
container.Register<IEmailTemplatesService>(() => new EmailTemplatesService(emailTemplates,
container.GetInstance<IEventEmailTemplatesRepository>(),
container.GetInstance<IEmailTemplatesRepository>(),
container.GetInstance<IEventSettingsRepository>(),
container.GetInstance<IEmailsService>(),
container.GetInstance<IUnitOfWork>(),
container.GetInstance<IValidationProvider>()));
container.RegisterCollection<IStreamingMethod>(new List<IStreamingMethod>
{
new CubeProvider(container.GetInstance<ILogger>()),
new BallerTvProvider(container.GetInstance<ILogger>())
});
You are getting this error because you are calling GetInstance during your container setup. As the exception and the referenced documentation explain, this is not allowed.
The problem is caused by you trying to partially hand-wire your registrations, while you should prefer letting Simple Injector do the heavy lifting and Auto-Wire everything for you. You should therefore change your registration to the following:
container.Register<IEmailTemplatesService, EmailTemplatesService>();
container.RegisterCollection<IStreamingMethod>(new[]
{
typeof(CubeProvider),
typeof(BallerTvProvider)
});
I'm following this OData V4 tutorial and now have a problem with the bound function MostExpensive.
This function is bound to the Productscollection and is registered in WebApiConfig.Register() like suggested in the tutorial:
ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
builder.Namespace = "ProductService";
builder.EntityType<Product>().Collection.Function("MostExpensive").Returns<decimal>();
There is only described a rudimentary client for this service in part 2 of this tutorial. So I want to extend it so that I also can call the functions described in the later parts of the tutorial.
I have created the client using OData Client Code Generator as suggested in the tutorial. I then add some products and suppliers and then want to get the most expensive product:
static void Main(string[] args)
{
const string serviceUri = "http://localhost:52542";
Container container = new Container(new Uri(serviceUri));
AddProducts(container, GenerateSomeProducts());
AddSuppliers(container, GenerateSomeSuppliers());
Console.WriteLine("Most expensive product is: {0}", container.Products.MostExpensive().GetValue());
...
}
When calling GetValue() I am getting an InvalidOperationException stating that http://localhost:52542/$metadata refers to a Edm.Decimal type but a Collection(Edm-Decimal) type is expected.
When calling http://localhost:52542/Products/ProductService.MostExpensive() directly in the browser I'm getting
{
"#odata.context":"http://localhost:52542/$metadata#Edm.Decimal","value":40000.95
}
Which seems to be correct.
Do I do anything wrong? I have no idea how to fix this. So any suggestions about that?
I guess you are using T4 2.2.0, right?
There is a bug in T4 2.2.0 which causes this issue. You can use the content in following link to replace your ttinclude file and regenerate your proxy to work around the issue.
https://raw.githubusercontent.com/LaylaLiu/odata.net/T4TempFix/src/CodeGen/ODataT4CodeGenerator.ttinclude
I am trying to create a webAPI with Visual Studio 2012. I've followed the provided Microsoft ASP.NET tutorial.
So I've got the class, repository and controller down. The software is able to to run and connect with the database. When I run and make the API call, this error occurs:
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[ReservationsAPI.Contact]' to type 'System.Collections.Generic.IEnumerable`1[ReservationsAPI.Models.Contacts]'.
This error occurs in the method below in my repository file:
public IEnumerable<Contacts> GetAll()
{
var ContactsAll = from c in rdbc.Contacts select c;
return (IEnumerable<Contacts>)ContactsAll;
}
The error occurs at the return line. I am not sure how to deal with this error.
In your method's return type, change the type Contacts to Contact without the s. You can see this in the error message that it needs to be Contact.