KeyNotFoundException with RavenDb - asp.net-mvc-5

Just installed RavenDb Build-3528 as a Website in IIS.
RavenDb is running just fine, management studio is reachable on http://localhost:8080, created databases etc, so far no problem.
However when I start my MVC 5 application (with regular MVC Controllers and WebApi Controllers) the application crashes on startup with the json message:
{
message: "An error has occurred.",
exceptionMessage: "The given key was not present in the dictionary.",
exceptionType: "System.Collections.Generic.KeyNotFoundException",
stackTrace: " at System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key) at Raven.Database.Server.Controllers.RavenBaseApiController.InnerInitialization(HttpControllerContext controllerContext) in c:\Builds\RavenDB-Stable-3.0\Raven.Database\Server\Controllers\RavenBaseApiController.cs:line 101 at Raven.Database.Server.Controllers.RavenDbApiController.InnerInitialization(HttpControllerContext controllerContext) in c:\Builds\RavenDB-Stable-3.0\Raven.Database\Server\Controllers\RavenDbApiController.cs:line 112 at Raven.Database.Server.Controllers.RavenDbApiController.<ExecuteAsync>d__3a.MoveNext() in c:\Builds\RavenDB-Stable-3.0\Raven.Database\Server\Controllers\RavenDbApiController.cs:line 54 --- 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 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
Funny thing is: before installing RavenDb as Website in IIS we used RavenDb 2.5 as embedded server in our MVC application and worked just fine.
In the Windows Event Manager I can't find any useful information.
Anyone an idea what's going on?

Hah!
It turns out that if you comment out the following line in WebApiConfig.cs that error disappears:
// Web API routes
config.MapHttpAttributeRoutes(); // <--- Offending line
Apparently RavenDB calls MapHttpAttributeRoutes() as well so there's a conflict...
Of course, commenting out that line means that the WebApi routes no longer work, throwing an Multiple actions were found that match the request error.
UPDATE
On my solution there is a project with Unit Tests that requires Raven.Database.dll because it uses the EmbeddableDocumentStore to run tests in memory.
This Raven.Database.dll ends up on the bin folder of the MVC/WebApi project. As soon as you delete it, the website works. So it really is the EmbeddableDocumentStore wrecking havoc with WebApi.
In short, make sure you have no references to Raven.Database.dll in your WebApi projects, and that the dll doesn't end up in the bin of your WebApi project either (by setting Copy to Local = false, for instance).
UPDATE 2
It turns out that somehow my main project had a reference to the test project, that's why Raven.Database.dll ended up in my main project's bin folder. Just removing that unnecessary reference does the trick, no neet to set Copy to Local = false.

Related

ABP framework 6.0.0 fails when deployed at Azure

Trying to deploy ABP framework 6.0.0 AuthServer at Azure, after sucessful built and run locally.
Got "HTTP Error 500.30 - ASP.NET Core app failed to start"
When trying to get some logs, using Azure Debug Console at myproject.scm.azurewebsites.net/DebugConsole I got following:
C:\home\site\wwwroot>dotnet MyProject.AuthServer.dll
[19:52:57 INF] Starting MyProject.AuthServer.
[19:53:00 FTL] MyProject.AuthServer terminated unexpectedly!
Volo.Abp.AbpInitializationException: An error occurred during ConfigureServicesAsync phase of the module Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule, Volo.Abp.OpenIddict.AspNetCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=null. See the inner exception for details.
---> Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Access is denied.
at Internal.Cryptography.Pal.StorePal.FromSystemStore(String storeName, StoreLocation storeLocation, OpenFlags openFlags)
at System.Security.Cryptography.X509Certificates.X509Store.Open(OpenFlags flags)
at Microsoft.Extensions.DependencyInjection.OpenIddictServerBuilder.AddDevelopmentEncryptionCertificate(X500DistinguishedName subject)
at Microsoft.Extensions.DependencyInjection.OpenIddictServerBuilder.AddDevelopmentEncryptionCertificate()
at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.<>c__DisplayClass1_0.<AddOpenIddictServer>b__0(OpenIddictServerBuilder builder)
at Microsoft.Extensions.DependencyInjection.OpenIddictServerExtensions.AddServer(OpenIddictBuilder builder, Action`1 configuration)
at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.AddOpenIddictServer(IServiceCollection services)
at Volo.Abp.OpenIddict.AbpOpenIddictAspNetCoreModule.ConfigureServices(ServiceConfigurationContext context)
at Volo.Abp.Modularity.AbpModule.ConfigureServicesAsync(ServiceConfigurationContext context)
at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync()
--- End of inner exception stack trace ---
at Volo.Abp.AbpApplicationBase.ConfigureServicesAsync()
at Volo.Abp.AbpApplicationFactory.CreateAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionApplicationExtensions.AddApplicationAsync[TStartupModule](IServiceCollection services, Action`1 optionsAction)
at Microsoft.Extensions.DependencyInjection.WebApplicationBuilderExtensions.AddApplicationAsync[TStartupModule](WebApplicationBuilder builder, Action`1 optionsAction)
at MyProject.Program.Main(String[] args) in D:\a\1\s\aspnet-core\src\MyProject.AuthServer\Program.cs:line 35
This say nothing to me, and when Googling around, I hit this at abp.io website: https://support.abp.io/QA/Questions/3537/OpenIddict-WindowsCryptographicException-Access-is-denied
But I can´t figure out where I shall do the changes. It feels like this should be noted in the ABP.io docs?
Do you know what can cause this, or have some ideas what can be wrong?
I was having the same issue with having the same setup as you have with the exception of deploying to azure, but it should be the same solution.
Please check this SO question:
WindowsCryptographicException: Access is denied when publishing app in Azure
The problem with OpenIddict (or rather, the goodness we're not used to) is that it is bare bones and you have to implement everything yourself.
OpenIddict must have a certificate in order to function on the server you're deploying to, and to have better security on top of whatever measures you're taking.
Basically what you will do is create a new self-signed certificate, upload it to cert store, add the thumbprint to the code and add it to one WEBSITE_LOAD_CERTIFICATES environment variable on said server.
You can add this environment variable to the code instead of hard-coding the thumbprint.
Here is a not-so-informative part of the abp.io documentation about the issue at hand:
Abp.io doc
And here is what I did in the code:
I hope this helps.

Error while publishing website ASP net core website

I've developed a ASP .net core (3.1) application which is successfully running locally, Now I'm trying to publish the web app through Visual Studio 2019, but getting error as:
An error occurred while processing your request.
Development Mode
Swapping to the Development environment displays detailed information about the error that occurred.
The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.
I've already tried adding value to "ASPNETCORE_ENVIRONMENT": "Production"
I'm using connection string as below:
Data Source=MyDataSource;Initial Catalog=MyDatabase;Integrated Security=True
What you're seeing is the default ASP.NET Core error page, including the Development Mode message.
You will need to debug to find out what the problem is. One thing you can do is to access the exception that was thrown and the original request path in an error handler controller or page by using IExceptionHandlerPathFeature:
var exceptionHandlerPathFeature = HttpContext.Features.Get<IExceptionHandlerPathFeature>();
if (exceptionHandlerPathFeature?.Error is FileNotFoundException)
{
ExceptionMessage = "File error thrown";
}
if (exceptionHandlerPathFeature?.Path == "/index")
{
ExceptionMessage += " from home page";
}
Here's more info on how to Handle errors in ASP.NET Core.
Some pointers based on the information you provided:
Is your data source MyDataSource available through the internet (with the name you specified)?
Does your data source really provide Integrated Security with an ASP.NET application in Azure?
Enable logging (like Application Insights for ASP.NET Core applications) to find the issue

how to debug error 500 Internal Server Error on an Azure App?

I got an "500 Internal Server Error - An error occurred while starting the application" after deploying my application: https://iidapp.azurewebsites.net/
I keep finding the following error message but I am unable to find out on msdn websites any information describing how I can specify the SAS URL
INFO: The app was working for a long period and I didn't have to set the SAS URL; I wonder why suddenly Azure is generating exceptions
INFO2: the app works perfectly on my local machine
Any help is welcomed as I couldn't find any solution by reading the related topics on stackoverflow
2017-04-05T18:51:32
System.ApplicationException: The trace listener AzureBlobTraceListener is disabled. ---> System.InvalidOperationException: The SAS URL for the cloud storage account is not specified. Use the environment variable 'DIAGNOSTICS_AZUREBLOBCONTAINERSASURL' to define it.
at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.RefreshConfig()
--- End of inner exception stack trace ---
An error was triggered by W3SVC-WP : {app name}02000780
I found out on eventid that the code 02000780 meant that a file was missing
I eventually found out that it was possible to log further information by enabling the stdoulog inside the web.config. Read When a .NET Core Azure App Service won’t start: 502.5 Process Failure
I opened the debug console and found out that a directory wasn't found https://{app_id}.scm.azurewebsites.net/DebugConsole
Voilà! I corrected the code and the app is up and running!

Server Error in '/DotNetNuke_Community' Application

I'm getting the following error when attempting to run DotNetNuke 7.1 from IIS.
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 572: //first call GetProviderPath - this insures that the Database is Initialised correctly
Line 573: //and also generates the appropriate error message if it cannot be initialised correctly
Line 574: string strMessage = DataProvider.Instance().GetProviderPath();
Line 575: //get current database version from DB
Line 576: if (!strMessage.StartsWith("ERROR:"))
I've tried running it from Visual Studio 2012 after downloading and extracting the source code to a folder, then running, but I get the same error (also, VS loads about 13 instances of it's built in webserver which can't be correct).
Clearly, there is something wrong with the database. From what I've read in the past, there should have been a start up configuration page (for configuring settings the first time you run the project).
I did look at the local version of IIS (running on Windows 8) and it created the site fine there, however, for some reason the internal webserver attempts to run (and the option to run on an external IIS is greyed out).
Anyone run into this problem with DNN Community edition? I've tried running as admin and setting permissions with no luck at all.
Any way to fix this?
Ok, the key is to delete the Database.mdf file completely.
Then create a new empty database of your choice in SQL Server (2008 or greater).
Create a new user account with db_owner access (as it must be able to create tables, etc).
Change the connection strings in the release.config and development.config to connect to the database.
DELETE the web.config file.
RENAME either config file to "web.config"
Set the default project to the web project in VS
set the default page to default.aspx
Run
I made the erroneous assumption that running the app would rename the config file for me (not sure why I assumed that).
SOLVED!

Orchard CMS Multi-tenancy crash beware

I'm sporting Orchard 1.4 up with Multi-tenancy enabled. I added a new tenant this morning with a name that started with the number 4, "4wdcarsandtrucks". Well, after creating the new tenant, all my sites started throwing 404 errors. Looking into the logs, I found that I was getting the following entries for every one of my tentants:
2012-05-20 08:59:22,795 [6] Orchard.Environment.DefaultOrchardHost - A
tenant could not be started: Default System.Xml.XmlException: Name
cannot begin with the '4' character, hexadecimal value 0x34. Line 16,
position 4. at System.Xml.XmlTextReaderImpl.Throw(String res,
String[] args) at System.Xml.XmlTextReaderImpl.ParseQName(Boolean
isQName, Int32 startOffset, Int32& colonPos) at
System.Xml.XmlTextReaderImpl.ParseElement() at
System.Xml.XmlTextReaderImpl.ParseElementContent() at
System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at
System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc) at
System.Xml.XmlDocument.Load(XmlReader reader) at
System.Xml.XmlDocument.LoadXml(String xml) at
Orchard.Environment.Descriptor.ShellDescriptorCache.Fetch(String name)
in
C:\src\xxxxxx\main\dotnet\public\Orchard\v1.4.1.0\src\Orchard\Environment\Descriptor\ShellDescriptorCache.cs:line
53 at
Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings
settings) in
C:\src\xxxxx\main\dotnet\public\Orchard\v1.4.1.0\src\Orchard\Environment\ShellBuilders\ShellContextFactory.cs:line
54 at
Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in
C:\src\xxxxxx\main\dotnet\public\Orchard\v1.4.1.0\src\Orchard\Environment\DefaultOrchardHost.cs:line
135
As per instructions of removing tentants manually, I deleted the site folder in App_Data\Sites and the issue still persists.
I did a search under the orchard root folder for "4wdcarsandtrucks" and found another folder in Media. With that removed, the only remaining traces of the tenant name, the issues still persists. I've Recycled the app pool and restarted the site. It's so bizarre!
Has anyone run into this issue before or anyone have any advice?
Issue resolved! Okay, in case anyone else runs into this, there is some bizzare caching surrounding this issue. The following steps should clear it right up:
Stop the application pool.
Delete App_Data\cache.dat
Start the application pool.
I had a local copy of server's side Orchard CMS and I had an uninitialized tenant on my azure server. After downloading it, it either wanted to set up a new webpage (default setup screen on an already working system) or it threw
a tenant could not be started
But deleting cache.dat in App_Data folder of my orchard directory (locally) fixed the issue.

Resources