I am trying to create a project. That’s why I downloaded a startup template from this link. Then I tried to configure with asp.net core. I set the connection string as "Default": "User ID=postgres;Password=**********;Host=localhost;Port=5432;Database=LibraryManagementDb;Pooling=true;". and then changed UseSqlServer to UseNpgsql in LibraryManagementDbContextConfigurer class.
`
public static void
Configure(DbContextOptionsBuilder<LibraryManagementDbContext>
builder, string connectionString)
{
builder.UseNpgsql(connectionString);
}
public static void
Configure(DbContextOptionsBuilder<LibraryManagementDbContext>
builder, DbConnection connection)
{
builder.UseNpgsql(connection);
}
`
and add the below code to DbContext class
`
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ApplicationLanguageText>()
.Property(p => p.Value)
.HasMaxLength(100); // any integer that is smaller than 10485760
}
`
and removed all migration classes from the Migration folder and run add-migration Initial_Migration command in the package manager console
but I got the Exception has been thrown by the target of an invocation. error
this is the whole exception
`
PM> add-migration Initial_Migration Build started... Build succeeded. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeLoadException: Method 'get_Info' in type 'Microsoft.EntityFrameworkCore.Infrastructure. Internal.NpgsqlOptionsExt ension' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL, Version=2.1.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' does not have an implementation. at Microsoft.EntityFrameworkCore .NpgsqlDbContextOptionsExtensions.UseNpgsql[TContext] at LibraryManagement.EntityFrameworkCore .LibraryManagementDbContextConfigurer .Configure(DbContextOptionsBuilder`1 builder, String connectionString) in D:6.0.0aspnet- coresrcLibraryManagement.EntityFrameworkCore EntityFrameworkCoreLibraryManagementDbContextConfigurer.cs:line 10 at LibraryManagement.EntityFrameworkCore .LibraryManagementDbContextFactory.CreateDbContext(String[] args) in D:6.0.0aspnet-coresrcLibraryManagement.EntityFrameworkCore EntityFrameworkCoreLibraryManagementDbContextFactory.cs:line 17 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Microsoft.EntityFrameworkCore.Design .Internal.DbContextOperations.CreateContextFromFactory(Type factory, Type contextType) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations. <>c__DisplayClass16_0.<FindContextFactory>b__1() at Microsoft.EntityFrameworkCore.Design.Internal .DbContextOperations.CreateContext(Func`1 factory) at Microsoft.EntityFrameworkCore.Design.Internal .DbContextOperations.CreateContext(String contextType) at Microsoft.EntityFrameworkCore.Design.Internal .MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor .AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor .AddMigration.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor .OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor .OperationBase.Execute(Action action) Exception has been thrown by the target of an invocation.
`
How can I resolve this??? Please help…
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
By updating ‘Npgsql.EntityFrameworkCore.PostgreSQL’ solved this problem
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0