Could not load type 'Microsoft.EntityFrameworkCore.Query.RelationalQueryContextFactory' Z.EntityFramework.Plus.EFCore - entity-framework-core

I have written a simple query which was working when I was using .net core 2.1 (I have used Z.EntityFramework.Plus.EFCore)
int cnt = adminDb.Role.Where(c => c.RoleId == roleId).Delete();
After upgrading to .net core 3.1 I am getting the error below.
Could not load type 'Microsoft.EntityFrameworkCore.Query.RelationalQueryContextFactory' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Source : Z.EntityFramework.Plus.EFCore
StackTrace : at Z.EntityFramework.Plus.InternalExtensions.GetDbContext[T](IQueryable`1 source)
at Z.EntityFramework.Plus.BatchDelete.Execute[T](IQueryable`1 query)
at Z.EntityFramework.Plus.BatchDeleteExtensions.Delete[T](IQueryable`1 query, Action`1 batchDeleteBuilder)
at Z.EntityFramework.Plus.BatchDeleteExtensions.Delete[T](IQueryable`1 query)
at Assyst.Administration.API.Controllers.RoleMenuMappingController.SavePermission(Nullable`1 roleMenuMasterId, IList`1 roleMenu) in E:\Source\Main_Projects\Application\PanERP-7\Error\Administration\Admin\Controllers\RoleMenuMappingController.cs:line 365
I am receiving this error and I'm not sure what it means?

Related

Using $1 in the #Query throws exception: Cannot encode parameter of type org.springframework.r2dbc.core.Parameter

I'm using R2DBC in my project. After upgrading to Spring Boot from 2.5.* to 2.6.1 my query:
#Query("SELECT EXISTS(SELECT 1 FROM some_link links WHERE links.data_id = $1 AND links.some_id != links.source_id)")
fun existsByDataIdAndLocked(dataId: UUID): Mono<Boolean>
Throws an exception:
Suppressed: java.lang.IllegalArgumentException: Cannot encode parameter of type org.springframework.r2dbc.core.Parameter
at io.r2dbc.postgresql.codec.DefaultCodecs.encode(DefaultCodecs.java:192)
at io.r2dbc.postgresql.ExtendedQueryPostgresqlStatement.bind(ExtendedQueryPostgresqlStatement.java:89)
at io.r2dbc.postgresql.ExtendedQueryPostgresqlStatement.bind(ExtendedQueryPostgresqlStatement.java:47)
at org.springframework.r2dbc.core.DefaultDatabaseClient$StatementWrapper.bind(DefaultDatabaseClient.java:544)
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
at org.springframework.data.r2dbc.repository.query.StringBasedR2dbcQuery$ExpandedQuery.bindTo(StringBasedR2dbcQuery.java:227)
at org.springframework.r2dbc.core.DefaultDatabaseClient$DefaultGenericExecuteSpec.lambda$execute$2(DefaultDatabaseClient.java:334)
at org.springframework.r2dbc.core.DefaultDatabaseClient$DefaultGenericExecuteSpec.lambda$execute$3(DefaultDatabaseClient.java:374)
at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:46)
at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:31)
at org.springframework.r2dbc.core.DefaultFetchSpec.lambda$all$2(DefaultFetchSpec.java:88)
at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:46)
at org.springframework.r2dbc.core.ConnectionFunction.apply(ConnectionFunction.java:31)
at org.springframework.r2dbc.core.DefaultDatabaseClient.lambda$inConnectionMany$6(DefaultDatabaseClient.java:138)
at reactor.core.publisher.FluxUsingWhen.deriveFluxFromResource(FluxUsingWhen.java:119)
at reactor.core.publisher.FluxUsingWhen.access$000(FluxUsingWhen.java:53)
at reactor.core.publisher.FluxUsingWhen$ResourceSubscriber.onNext(FluxUsingWhen.java:194)
... 172 more
Once I change $1 in the query to :dataId then it works.
Why is that? As per documentation, both are valid.

Error resolving name servers Xamarin.Forms Android with MongoDB

I have the below issue connecting to Mongo Atlas when I set android:targetSDKVersion="28" in my android manifest.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: Error resolving name servers ---> System.ArgumentNullException: Value cannot be null.
Parameter name: source
at System.Linq.Enumerable.Where[TSource] (System.Collections.Generic.IEnumerable1[T] source, System.Func2[T,TResult] predicate) [0x0000d] in <715c2ff6913942e6aa8535593b3ef35a>:0
at DnsClient.NameServer.QueryNetworkInterfaces (System.Boolean skipIPv6SiteLocal) [0x00047] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
at DnsClient.NameServer.ResolveNameServers (System.Boolean skipIPv6SiteLocal, System.Boolean fallbackToGooglePublicDns) [0x0000d] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
--- End of inner exception stack trace ---
at DnsClient.NameServer.ResolveNameServers (System.Boolean skipIPv6SiteLocal, System.Boolean fallbackToGooglePublicDns) [0x0005e] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
at DnsClient.LookupClient..ctor () [0x00000] in <93b57b4b99c64a96a2c065ea9ae1fc1f>:0
at MongoDB.Driver.Core.Configuration.ConnectionString.Resolve (System.Boolean resolveHosts) [0x00011] in <861d33dc90734b91874371b41764f591>:0
at MongoDB.Driver.MongoUrl.Resolve (System.Boolean resolveHosts) [0x00015] in :0
at MongoDB.Driver.MongoClientSettings.FromUrl (MongoDB.Driver.MongoUrl url) [0x0001b] in :0
at MongoDB.Driver.MongoClientSettings.FromConnectionString (System.String connectionString) [0x00006] in :0
at MongoDB.Driver.MongoClient..ctor (System.String connectionString) [0x00000] in :0
If I remove the android:targetSDKVersion="28", the app connects without the issue but google play requires that I set the targetVersion before I can upload to play store.
I am using MongoDB Driver 2.91
Can you please help with possibly the solution.
Thanks.
I found out that from Android 8 (Oreo), access to net.dns has been removed. I was connecting to the server with SRV lookup according to the connection string from MongoDB 2.9 Driver. The DNSClient was Performing a DNS lookup on the domain name on the connection string. The below issue from DNSClient.net library shows more.
https://github.com/MichaCo/DnsClient.NET/issues/17
However, I had to do a custom implementation to get DNS Servers using the below code:
public List<IPEndPoint> GetDnsServers()
{
var context = Android.App.Application.Context;
List<IPEndPoint> endPoints = new List<IPEndPoint>();
ConnectivityManager connectivityManager =
(ConnectivityManager)context.GetSystemService(MainActivity.ConnectivityService);
Network activeConnection = connectivityManager.ActiveNetwork;
var linkProperties = connectivityManager.GetLinkProperties(activeConnection);
foreach (InetAddress currentAddress in linkProperties.DnsServers)
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(currentAddress.HostAddress), 53);
endPoints.Add(endPoint);
}
return endPoints;
}
The issue is gone.

EF Core Include method not working

I recently updated to asp.net core 2.0. Since upgrading all my Linq queries using Include Method are failing, it is not translated properly to SQL.
For instance this:
var entities = helpTopicRepository.Entities.Include(x => x.HelpArticles).FirstOrDefault(t => topicIds.Any(a => a == t.Id));
is translated to:
SELECT x.HelpArticles.ART_ID,
x.HelpArticles.AVAILABLE,
x.HelpArticles.CONTENT,
x.HelpArticles.DISPLAYORDER,
x.HelpArticles.HELPFULNO,
x.HelpArticles.HELPFULYES,
x.HelpArticles.KEYWORDS,
x.HelpArticles.TITLE,
x.HelpArticles.TOPICID
FROM HELPARTICLE x.HelpArticles
which is results in the following error:
Devart.Data.Oracle.OracleException (0x80004005): ORA-00933: SQL
command not properly ended at Devart.Data.Oracle.ay.b() at
Devart.Data.Oracle.am.f() at Devart.Data.Oracle.am.e() at
Devart.Data.Oracle.c5.a(am A_0, Int32 A_1) at
Devart.Data.Oracle.c5.a(Int32 A_0, bg A_1) at
Devart.Data.Oracle.OracleCommand.InternalExecute(CommandBehavior
behavior, IDisposable disposable, Int32 startRecord, Int32 maxRecords,
Boolean nonQuery) at
Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior
behavior, Boolean nonQuery) at
Devart.Data.Oracle.Entity.ai.a(CommandBehavior A_0) at
Devart.Common.Entity.cj.d(CommandBehavior A_0) at
Devart.Data.Oracle.Entity.ai.b(CommandBehavior A_0) at
System.Data.Common.DbCommand.ExecuteReader() at
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection
connection, DbCommandMethod executeMethod, IReadOnlyDictionary2
parameterValues) at
Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection
connection, IReadOnlyDictionary2 parameterValues) at
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(Boolean
buffer) at
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext()
at
Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.IncludeCollection(Int32
includeId, INavigation navigation, INavigation inverseNavigation,
IEntityType targetEntityType, IClrCollectionAccessor
clrCollectionAccessor, IClrPropertySetter inverseClrPropertySetter,
Boolean tracking, Object entity, Func1 relatedEntitiesFactory) at
lambda_method(Closure , QueryContext , Client , Object[] ) at
Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler._Include[TEntity](QueryContext
queryContext, TEntity entity, Object[] included, Action3 fixup) at
lambda_method(Closure , Client ) at
System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at
System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)
at lambda_method(Closure , QueryContext ) at
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass17_0`1.b__0(QueryContext
qc) ORA-00933: SQL command not properly ended
I'm using Devart dotconnect to connect to Oracle database.
Is due to your statement:
var entities = helpTopicRepository.Entities.Include(x => x.HelpArticles).FirstOrDefault(t => topicIds.Any(a => a == t.Id));
Assuming that topicIds is a list, here is a fix:
var entities = helpTopicRepository.Entities
.Include(x => x.HelpArticles)
.Where(t => topicIds.Contains(t.Id))
.FirstOrDefault();
The bug with using multiple .Include() in EF Core 2 is fixed. Look forward to the next public build of dotConnect for Oracle.

How do I use DotNet Migrations in .Net Core when my Model and Repository are in a class library?

I am following this article/tutorial on how to make a generic repository for ASP.Net Core at:
http://www.c-sharpcorner.com/article/generic-repository-pattern-in-asp-net-core/
When I download the code I am able to run the migrations and the project runs and works.
But when I follow the directions and try to build from scratch, then when I get to the point where I have to run the migrations:
Add-migration MyFirstMigration
I get this error:
C:\Tutorials\ASP.Net\Core\GenericRepository\FromScratch\GenericReposotory\GR.Web\project.json(20,43): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore 1.1.0 expected Microsoft.Extensions.Logging >= 1.1.0 but received 1.0.0 No parameterless constructor was found on 'ApplicationContext'. Either add a parameterless constructor to 'ApplicationContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ApplicationContext'.
The tutorial had the model and repo defined in a class library including this:
namespace GR.Data
{
public class ApplicationContext : DbContext
{
public ApplicationContext(DbContextOptions<ApplicationContext> options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder){
base.OnModelCreating(modelBuilder);
new AuthorMap(modelBuilder.Entity<Author>());
new BookMap(modelBuilder.Entity<Book>());
}
}
}
The options are passed in from StartUp.cs in the Web Project like this:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
services.AddDbContext<ApplicationContext>(
options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
}
And it gets the connection string from appsettings.json in the Web Project: GR.Web.
In the Package Manager Console I have GR.Data selected as the default project and GR.Web set as the startup project. I get this error:
C:\Tutorials\ASP.Net\Core\GenericRepository\FromScratch\GenericReposotory\GR.Web\project.json(20,43): warning NU1012: Dependency conflict. Microsoft.EntityFrameworkCore 1.1.0 expected Microsoft.Extensions.Logging >= 1.1.0 but received 1.0.0 No parameterless constructor was found on 'ApplicationContext'. Either add a parameterless constructor to 'ApplicationContext' or add an implementation of 'IDbContextFactory' in the same assembly as 'ApplicationContext'.
How is the download working and how do I get mine to work.
so confused.
On top of it I had to fool around with it forever to get all the depenanceies on EF Core and Tools Preview on the right versions to get this far.
Is there a better article somewhere on how to do this?
I fixed:
"Microsoft.Extensions.Logging": "1.0.0",
to
"Microsoft.Extensions.Logging": "1.1.0",
and now I get this error:
System.TypeLoadException: Method 'Apply' in type 'Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationalColumnAttributeConvention' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation. at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationalConventionSetBuilder.AddConventions(ConventionSet conventionSet)
at Microsoft.EntityFrameworkCore.Metadata.Conventions.SqlServerConventionSetBuilder.AddConventions(ConventionSet conventionSet)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.LazyRef1.get_Value()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action1 reporter)
at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
Method 'Apply' in type 'Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.RelationalColumnAttributeConvention' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not ha ve an implementation.
In dependancies for the Web Project, GR.Web, I rolled back
"Microsoft.EntityFrameworkCore": "1.1.0"
to
"Microsoft.EntityFrameworkCore": "1.0.1"
and now it works.

Could not load type 'Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy' when installing on Sitefinity 8.1.5800

I am trying to install Babaganoush on Sitefinity 8.1.5800 which has assembly redirects in place. I am getting the exception below and would like to know if anyone else has seen this?
Could not load type 'Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy' from assembly 'Telerik.Sitefinity, Version=8.1.5800.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy' from assembly 'Telerik.Sitefinity, Version=8.1.5800.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[TypeLoadException: Could not load type 'Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy' from assembly 'Telerik.Sitefinity, Version=8.1.5800.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'.]
Babaganoush.Sitefinity.Utilities.ConfigHelper.RegisterToolboxWidget(String title, String description, String cssClass, String resourceClassId, String layoutTemplate, String sectionName, Nullable1 sectionOrdinal, ToolboxType toolboxType) +0
Babaganoush.Sitefinity.Mvc.Startup.OnBootstrapperInitialized(Object sender, ExecutedEventArgs e) +704
System.EventHandler1.Invoke(Object sender, TEventArgs e) +0
Telerik.Sitefinity.Abstractions.Bootstrapper.Bootstrap() +906
Telerik.Sitefinity.Web.SitefinityHttpModule.Init(HttpApplication context) +400
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +530
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Could not load type 'Telerik.Sitefinity.Mvc.Proxy.MvcControllerProxy' from assembly 'Telerik.Sitefinity, Version=8.1.5800.0, Culture=neutral, PublicKeyToken=b28c218413bdf563'.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12618692
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12458309
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34249
The MvcControllerProxy type is now in the Telerik.Sitefinity.Mvc assembly.
You'll probably have to wait for the guys at Falafel to release a version that targets Sitefinity 8.1