I am using VS2013 community edition, SQLite and created Test project using MSTestFramework where I am referring MoqRT framework for creating mock objects.
But while creating mock objects I am getting an Error as follows,
Unhandled baking exception: --> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DllNotFoundException: Unable to load DLL 'sqlite3': This operation is only valid in the context of an application container. (Exception from HRESULT: 0x8007109A)
at SQLite.SQLite3.Open(String filename, IntPtr& db)
at SQLite.SQLiteConnection..ctor(String databasePath)
at MoqRT.Baking.BakingController.GetDatabase()
at MoqRT.Baking.BakingController..ctor(String testAssembly, String appxPath, String bakingPath)
at MoqRT.MoqRTRuntime.InitializeBaking(String testAssembly, String appxPath, String bakingPath)
--- End of inner exception stack trace ---
Server stack trace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
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 MoqRT.Baking.BakingWorkItem.Run(BakingContext context) in d:\Kierron Matte\Projects\Mercury\R & D\Unit Testing\MoqRT-master\MoqRT.Baker\Controller\BakingWorkItem.cs:line 35
at MoqRT.Baking.BakingPoke.RunWorkItem(BakingController owner, WorkItem item) in d:\Kierron Matte\Projects\Mercury\R & D\Unit Testing\MoqRT-master\MoqRT.Baker\Controller\BakingPoke.cs:line 36
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at MoqRT.Baking.IBakingPoke.RunWorkItem(BakingController owner, WorkItem item)
at MoqRT.Baking.BakingRunner.ThreadEntryPoint() in d:\Kierron Matte\Projects\Mercury\R & D\Unit Testing\MoqRT-master\MoqRT.Baker\Controller\BakingRunner.cs:line 55
I had referred the project and steps from GitHub "/mbrit/moqrt"
but not able to create MoqRT.Baked.dll.
I have referred the following files in my test project,
MoqRT.MetroStyle.dll
MoqRT.MetroStyle.pdb
MoqRT.MetroStyle.pri
I have also added the image for your reference.
Thanks in advance.
Unhandled Exception while Creating MoqRT.Baked.dll
I have resolved this issue by removing additional SQLite (For Windows RunTime) reference from my Test Project which was not similar as used by MoqRT version (SQLite3.dll).
Related
I'm getting this error when publishing my Blazor Server application after adding file uploads.
My project is using .net5
In my startup.cs file I have this code, in which if commented out, causes no errors. If I comment it out and publish the application works again but obviously file uploads stop working.
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "Files")),
RequestPath = "/Files"
});
app.UseRouting();
Further I will share the logged errors. They basically point back to line '86' which is where this code is. I can run the application IIS locally and it runs just fine, but breaks when published.
Logged errors from Azure Event Logs
Source: IIS AspNetCore Module V2
Application '/LM/W3SVC/665542692/ROOT' with physical root 'D:\home\site\wwwroot\' failed to load coreclr. Exception message:
CLR worker thread exited prematurely
Process Id: 19728.
File Version: 15.0.21196.9. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: c663adee8e64ba5d379fa0edfb8201984a7df7d0
Source: IIS AspNetCore Module V2
Application '/LM/W3SVC/665542692/ROOT' with physical root 'D:\home\site\wwwroot\' hit unexpected managed exception, exception code = '0xe0434352'. First 30KB characters of captured stdout and stderr logs:
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
Application startup exception
System.IO.DirectoryNotFoundException: D:\home\site\wwwroot\Files\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at BlazorApp1.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Startup.cs:line 86
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 Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
Unhandled exception. System.IO.DirectoryNotFoundException: D:\home\site\wwwroot\Files\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at BlazorApp1.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Startup.cs:line 86
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 Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at BlazorApp1.Program.Main(String[] args) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Program.cs:line 18
Process Id: 19728.
File Version: 15.0.21196.9. Description: IIS ASP.NET Core Module V2 Request Handler. Commit: c663adee8e64ba5d379fa0edfb8201984a7df7d0
Source: .NET runtime
Application: w3wp.exe
CoreCLR Version: 5.0.921.35908
.NET Version: 5.0.9
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.DirectoryNotFoundException: D:\home\site\wwwroot\Files\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at BlazorApp1.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Startup.cs:line 86
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 Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
at BlazorApp1.Program.Main(String[] args) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Program.cs:line 18
Source: .NET Runtime
Category: Microsoft.AspNetCore.Hosting.Diagnostics
EventId: 6
Application startup exception
Exception:
System.IO.DirectoryNotFoundException: D:\home\site\wwwroot\Files\
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
at BlazorApp1.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in F:\Documents\GitHub\WahlenApp\BlazorApp1\Startup.cs:line 86
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 Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
I have done a bunch of searching and find that I'm not the only one that has run into this problem in the past. I tried many suggested 'solutions', but to no avail.
I found the answer to my issue.
In my .csproj file.
I have this line.
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" Version="12.10.0" />
</ItemGroup>
I downgraded to version 12.8.0 and it now works when published. I would assume something in how this function needs to be coded has changed since the older version.
Currently having a problem with NSwag generation on a custom authorize attribute. I have been completely unable to find anything on this issue elsewhere.
I've created a custom attribute for my WebAPI and more or less followed the patterns recommended here
internal class AuthorizeWithPermissionAttribute : AuthorizeAttribute
{
const string POLICY_PREFIX = "HasPermission";
public AuthorizeWithPermissionAttribute(string permission) { // logic excluded for brevity }
public string Permission
{
get { // code }
set { // code }
}
}
Then I decorate my controller with this attribute like so
[AuthorizeWithPermission("MY_PERMISSION_NAME")]
public class MyController: ControllerBase
{
// Controller logic.
}
So far I have tried
Creating a public parameterless constructor on the attribute
Changing the type (enum, int, string) of the constructor param
Applying [OpenApiIgnore] to the type and then writing a custom filter in Startup.cs when that didn't work
Changing the access modifier at the class and property level
Applying the attribute broadly to the controller and methods directly.
Here is the error I'm getting:
Executing file 'nswag.json' with variables 'Configuration=Debug'...
3> Launcher directory: %UserDirectory%\.nuget\packages\nswag.msbuild\13.8.2\tools\NetCore31
3> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
3> ---> System.NullReferenceException: Object reference not set to an instance of an object.
3> at %SLNNAME%.Authorization.Attributes.AuthorizeWithPermissionAttribute..ctor(String permission) in %SLNDirectory%\Authorization\Attributes\AuthorizeWithPermissionAttribute.cs:line 14
3> at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
3> at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, RuntimeType type, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
3> at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
3> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType)
3> at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
3> at System.RuntimeType.GetCustomAttributes(Boolean inherit)
3> at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.CreateControllerModel(TypeInfo typeInfo)
3> at Microsoft.AspNetCore.Mvc.ApplicationModels.DefaultApplicationModelProvider.OnProvidersExecuting(ApplicationModelProviderContext context)
3> at Microsoft.AspNetCore.Mvc.ApplicationModels.ApplicationModelFactory.CreateApplicationModel(IEnumerable`1 controllerTypes)
3> at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.GetDescriptors()
3> at Microsoft.AspNetCore.Mvc.ApplicationModels.ControllerActionDescriptorProvider.OnProvidersExecuting(ActionDescriptorProviderContext context)
3> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.UpdateCollection()
3> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.Initialize()
3> at Microsoft.AspNetCore.Mvc.Infrastructure.DefaultActionDescriptorCollectionProvider.get_ActionDescriptors()
3> at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
3> at NSwag.Generation.AspNetCore.AspNetCoreOpenApiDocumentGenerator.GenerateAsync(Object serviceProvider)
3> at NSwag.AspNetCore.OpenApiDocumentProvider.GenerateAsync(String documentName)
3> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.GenerateDocumentWithDocumentProviderAsync(IServiceProvider serviceProvider) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 287
3> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.GenerateDocumentAsync(AssemblyLoader assemblyLoader, IServiceProvider serviceProvider, String currentWorkingDirectory) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 276
3> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.<>c__DisplayClass0_0.<<Process>b__0>d.MoveNext() in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 30
3> --- End of stack trace from previous location where exception was thrown ---
3> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToOpenApiGeneratorCommandEntryPoint.Process(String commandContent, String outputFile, String applicationName) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiGeneratorCommandEntryPoint.cs:line 29
3> --- End of inner exception stack trace ---
3> at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
3> at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
3> at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
3> at NSwag.AspNetCore.Launcher.Program.Main(String[] args) in C:\projects\nswag\src\NSwag.AspNetCore.Launcher\Program.cs:line 170
3> System.InvalidOperationException: Swagger generation failed with non-zero exit code '1'.
3> at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Generation\AspNetCore\AspNetCoreToOpenApiCommand.cs:line 221
3> at NSwag.Commands.NSwagDocumentBase.GenerateSwaggerDocumentAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocumentBase.cs:line 280
3> at NSwag.Commands.NSwagDocument.ExecuteAsync() in C:\projects\nswag\src\NSwag.Commands\NSwagDocument.cs:line 81
3> at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 86
3> at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in C:\projects\nswag\src\NSwag.Commands\Commands\Document\ExecuteDocumentCommand.cs:line 32
3> at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
3> at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
3> at NConsole.CommandLineProcessor.Process(String[] args, Object input)
3> at NSwag.Commands.NSwagCommandProcessor.Process(String[] args) in C:\projects\nswag\src\NSwag.Commands\NSwagCommandProcessor.cs:line 56
3> %SLNDirectory%.csproj(59,5): error MSB3073: The command "dotnet "%UserDirectory%\.nuget\packages\nswag.msbuild\13.8.2\build\../tools/NetCore31/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code -1.
3> Done executing task "Exec" -- FAILED.
LOGIC! LOGIC IN The constructor was the issue. Here this works. Hopefully someone won't spend two hours of their life on this like I did
public class AuthorizeWithPermissionAttribute : AuthorizeAttribute
{
const string POLICY_PREFIX = "HasPermission";
public AuthorizeWithPermissionAttribute(string permission)
{
this.Permission = permission;
}
public string Permission { get => Policy; set => Policy = $"{POLICY_PREFIX}{value}"; }
}
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.0\aspnet-
core\src\LibraryManagement.EntityFrameworkCore
\EntityFrameworkCore\LibraryManagementDbContextConfigurer.cs:line
10
at LibraryManagement.EntityFrameworkCore
.LibraryManagementDbContextFactory.CreateDbContext(String[] args)
in D:\6.0.0\aspnet-core\src\LibraryManagement.EntityFrameworkCore
\EntityFrameworkCore\LibraryManagementDbContextFactory.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...
By updating 'Npgsql.EntityFrameworkCore.PostgreSQL' solved this problem
I have a Asp.net Core 2.2 Odata Controller where I need to filter the name of persons with the "like" functionality. This errors out. Is this query support by MongoDB driver (ver 2.8.1) ?
http://192.168.1.151:5000/v2/odata/users?$filter=contains(Name, 'Smith')&$top=1&$count=true
If I I use exact or eq filter it works
http://192.168.1.151:5000/v2/odata/users?$filter=Name eq 'Smith Alan')&$top=1&$count=true
[10:30:17.208 ERR][0HLO4RQ58RQQ9:00000001] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: IIF((({document}{name} == null) OrElse False), null, Convert({document}{name}.Contains("Loi"), Nullable`1)) is not supported.
at MongoDB.Driver.Linq.Translators.PredicateTranslator.GetFieldExpression(Expression expression)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateComparison(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateOrderBy(OrderByExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateTake(TakeExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateTake(TakeExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at Microsoft.AspNet.OData.Query.TruncatedCollection`1..ctor(IQueryable`1 source, Int32 pageSize)
at Microsoft.AspNet.OData.Query.ODataQueryOptions.LimitResults[T](IQueryable`1 queryable, Int32 limit, Boolean& resultsLimited)
--- 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 Microsoft.AspNet.OData.Query.ODataQueryOptions.LimitResults(IQueryable queryable, Int32 limit, Boolean& resultsLimited)
at Microsoft.AspNet.OData.Query.ODataQueryOptions.ApplyTo(IQueryable query, ODataQuerySettings querySettings)
at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery(Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, Func`2 modelFunction, IWebApiRequestMessage request, Func`2 createQueryOptionFunction)
The fix for the problem is to add HandleNullPropagation to false.
[EnableQuery( HandleNullPropagation = HandleNullPropagationOption.False)]
public IActionResult Get()
{
return Ok(_db.MyMongoDataCollection().AsQueryable());
}
I have .NET Core 1.1.1 web project that I can't run properly. I'm compiling against .NET 452 or/and .NET 462, this project has several regular .NET libraries references. The exception that I'm getting is:
System.AggregateException was unhandled
HResult=-2146233088
Message=An error occurred while writing to logger(s).
Source=Microsoft.Extensions.Logging
StackTrace:
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.LoggerExtensions.LogCritical(ILogger logger, EventId eventId, Exception exception, String message, Object[] args)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
at ClientFacingWeb.Program.Main(String[] args) in E:\..\ClientFacingWeb\Program.cs:line 18
InnerException:
HResult=-2147467262
Message=Unable to cast object of type 'System.Configuration.Internal.ConfigurationManagerInternal' to type 'System.Configuration.TimeSpanValidator'.
Source=System
StackTrace:
at System.Configuration.ConfigurationManagerInternalFactory.get_Instance()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
at System.Diagnostics.TraceInternal.InitializeSettings()
at System.Diagnostics.TraceInternal.WriteLine(String message, String category)
at Microsoft.Extensions.Logging.Debug.DebugLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
InnerException:
The message being printed in the console is:
Compilation=DEBUG
Environment=Development
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.AggregateException: One or more errors occurred. ---> System.Configuration.ConfigurationErrorsException: The configuration is read only.
at System.Configuration.ConfigurationElementCollection.BaseRemoveAt(Int32 index)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Net.Configuration.SettingsSectionInternal.get_Section()
at System.Net.Sockets.Socket.InitializeSockets()
at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.CreateIPEndpoint(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
---> (Inner Exception #0) System.Configuration.ConfigurationErrorsException: The configuration is read only.
at System.Configuration.ConfigurationElementCollection.BaseRemoveAt(Int32 index)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Net.Configuration.SettingsSectionInternal.get_Section()
at System.Net.Sockets.Socket.InitializeSockets()
at System.Net.IPAddress.InternalParse(String ipString, Boolean tryParse)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.CreateIPEndpoint(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.Bind(ServerAddress address)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListenerPrimary.CreateListenSocket()
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<StartAsync>b__8_0(Object state)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.ListenerPrimary.<StartAsync>d__12.MoveNext()<---
If I remove those regular .NET references the project executes successfully.
I'm not able to identify which one of the references is causing the error.
I have look into the output window too see the loaded modules, and none of the loaded modules are different if I use, have or not my regular .NET project/library references.