Error while remove migration and update database entity framework core Exception while reading from stream - .net-core

I am working in dotnet core web api using restful service with entity framework code first approach. I am running one migration and when I run the migration using add-migration command then I get build succeeded but then when I try to update-database or rollback the migration using remove-migration I get the below error:
PM> remove-migration
Build started...
Build succeeded.
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
at Npgsql.NpgsqlReadBuffer.<>c__DisplayClass34_0.<<Ensure>g__EnsureLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.Authenticate(String username, NpgsqlTimeout timeout, Boolean async)
at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnection.Open()
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrations()
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>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 while reading from stream

This is resolved. I had a Factory class in which the connection string was not updated to my local database. There it was pointing to dev and my secret.json was pointing to localhost.

Related

EF Core and Postgresql generation expression is not immutable on modified_at column

I'm learning aspnet.core
In laravel we can do $table->timestamps() to generate created_at and modified_at to be updated automatically.
After searching, I found out that we can do this in EFCore (i'm using postgresql with npgsql
modelBuilder.Entity<User>()
.Property(u => u.created_at)
.HasDefaultValueSql("CURRENT_TIMESTAMP")
.ValueGeneratedOnAdd();
modelBuilder.Entity<User>()
.Property(u => u.modified_at)
.HasComputedColumnSql("CURRENT_TIMESTAMP")
.ValueGeneratedOnUpdate();
However I'm getting error:
Failed executing DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE "Users" ADD modified_at timestamp without time zone GENERATED ALWAYS AS (CURRENT_TIMESTAMP) STORED;
Npgsql.PostgresException (0x80004005): 42P17: generation expression is not immutable
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
I suspect the HasComputedColumnSql has couple of problem but I can't figure out why. Can anyone help?
Thanks

Error with publishing my ASP.net website

solved.
My solution: Build -> clean -> rebuild
I got host for my website and now I'm trying to upload the website's files via VS2017 using 'publish' feature of VS. I setup the connection with the host properly (Validate connection went successful..). But as the VS tries to upload my files it says:
Unable to add 'Content/homePage.css' to the Web site. Unable to parse server response to PASV command.
This error message is shown for each file in my website. The above is just an example to such message. I'm using FTP publish method. My host is 000webhost
diagnostic log:
15/07/2018 08:56:08
System.AggregateException: One or more errors occurred. ---> System.Exception: Publish failed due to build errors. Check the error list for more details.
--- 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.VisualStudio.Web.Publish.PublishService.VsWebProjectPublish.<>c__DisplayClass40_0.<PublishAsync>b__2()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- 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.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__88.MoveNext()
---> (Inner Exception #0) System.Exception: Publish failed due to build errors. Check the error list for more details.<---
===================

OrangeBits extension for WebMatrix may have caused a crash and has been disabled

I'm getting the following error every time I open WebMatrix with the OrangeBits extension installed:
The "OrangeBits" extension may have caused a crash and has been disabled. We recommend contacting the extension owner for assistance.
System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. ---> Ionic.Zip.ZipException: The file C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools\bin\cake already exists.
at Ionic.Zip.ZipEntry.CheckExtractExistingFile(String baseDir, String targetFileName)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipEntry.Extract(String baseDirectory)
at OrangeBits.OrangeBits.<>c__DisplayClass17.<UnpackModules>b__15()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of inner exception stack trace ---
---> (Inner Exception #0) Ionic.Zip.ZipException: The file C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools\bin\cake already exists.
at Ionic.Zip.ZipEntry.CheckExtractExistingFile(String baseDir, String targetFileName)
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password)
at Ionic.Zip.ZipEntry.Extract(String baseDirectory)
at OrangeBits.OrangeBits.<>c__DisplayClass17.<UnpackModules>b__15()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()<---
Referencing Justin Beckwith's answer here
Resolving this issue was as simple as navigating to:
C:\USERS\NAME\APPDATA\LOCAL\MICROSOFT\WEBMATRIX\EXTENSIONS\30\OrangeBits\Tools
And deleting modules.zip

RavenDB Error in IIS 7.5 / Windows 7 Home Premium

I can't get RavenDB to run in my local copy of IIS and I can't seem to find any information about it. I have the proper permissions set up on the folder and files and adjusted the Application pool as the set-up instructions stated but still it doesn't seem to work. The only (unhelpful) error I get is this:
Could not authenticate against the server
Message: [HttpWebRequest_WebException_RemoteServer]
Arguments: NotFound
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.1.10411.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer
Uri: /databases?database=Default
Server Uri: http://localhost:82/docs/Raven/Databases/Kiosk
-- Error Information --
System.Net.WebException: [HttpWebRequest_WebException_RemoteServer]
Arguments: NotFound
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.1.10411.0&File=System.Windows.dll&Key=HttpWebRequest_WebException_RemoteServer
at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Func`2.Invoke(T arg)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise)
Inner StackTrace:
at Raven.Studio.Infrastructure.InvocationExtensions.Catch(Task parent, Action`1 action)
at Raven.Studio.Infrastructure.InvocationExtensions.Catch(Task parent)
at Raven.Studio.Commands.CreateDatabaseCommand.<>c__DisplayClass3.<Execute>b__0(Task`1 task)
at System.Threading.Tasks.ContinuationTaskFromResultTask`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
This usually indicate that you didn't install/enabled Windows Auth in IIS

ActivationManager Exception during build process?

I'm getting the following exception when building a website project in VS 2010:
The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation..
How do I go about debugging this? It's happening when I build in VS.NET and from the command-line (e.g., via NAnt/MSBuild).
To solve this, you need to supply the -errorstack argument to the aspnetcompiler. Then when it fails, you'll get not only the stack trace of the exception you're seeing now, but also the InnerException that it's wrapping. For instance, here's the output when the build error is caused by a problem with a Cassette dll not being loaded:
error ASPRUNTIME: The pre-application start initialization method Run on type We
bActivator.ActivationManager threw an exception with the following error message
: Exception has been thrown by the target of an invocation..
[TypeLoadException]: Could not load type 'Cassette.Configuration.ICassetteConfig
uration' from assembly 'Cassette, Version=0.8.1.0, Culture=neutral, PublicKeyTok
en=null'.
at Cassette.Web.StartUp..cctor()
[TypeInitializationException]: The type initializer for 'Cassette.Web.StartUp' t
hrew an exception.
at Cassette.Web.StartUp.PreApplicationStart()
[TargetInvocationException]: Exception has been thrown by the target of an invoc
ation.
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Ob
ject target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAt
tributes, RuntimeType typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Obj
ect target, Object[] arguments, Signature sig, MethodAttributes methodAttributes
, RuntimeType typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisib
ilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invoke
Attr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at WebActivator.BaseActivationMethodAttribute.InvokeMethod()
at WebActivator.ActivationManager.RunActivationMethods[T]()
at WebActivator.ActivationManager.RunPreStartMethods()
at WebActivator.ActivationManager.Run()
[InvalidOperationException]: The pre-application start initialization method Run
on type WebActivator.ActivationManager threw an exception with the following er
ror message: Exception has been thrown by the target of an invocation..
at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`
1 methods)
at System.Web.Compilation.BuildManager.CallPreStartInitMethods()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appMan
ager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, Host
ingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception a
ppDomainCreationException)
[HttpException]: The pre-application start initialization method Run on type Web
Activator.ActivationManager threw an exception with the following error message:
Exception has been thrown by the target of an invocation..
at System.Web.Compilation.ClientBuildManager.EnsureHostCreated()
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuil
dManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.Precompiler.Main(String[] args)
I'd like to up-vote Xoltar's answer, but this is my first contribution to SO so I don't have the rep!
I had a very similar problem on our build-server (TeamCity), here's a clip from the build-log:
[00:10:39]: (MvcBuildViews target) ->
[00:10:39]: error ASPRUNTIME : The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message: Exception has been thrown by the target of an invocation.. [C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site\Project.Site.csproj]
[00:10:39]: 0 Warning(s)
[00:10:39]: 1 Error(s)
[00:10:39]: Time Elapsed 00:00:27.93
To diagnose the problem I ran ASPNET_COMPILER, using the -errorstack argument against what MSBUILD had generated for site. In this case:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_compiler -p "C:\TeamCity\buildAgent\work\1ee8c94c32e676ad\source\Project.Site" -v anything -errorstack
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.
error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation..
[FileNotFoundException]: Could not load file or assembly 'msshrtmi, Version=1.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.InitializeEnvironment()
at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment..cctor()
error ASPRUNTIME: The pre-application start initialization method Run on type WebActivator.ActivationManager threw an exception with the following error message : Exception has been thrown by the target of an invocation..
In my case a dependency on one of the Azure assemblies (which wasn't installed on the build server) was the root of the problem.
Increase the verbosity level of the msbuild task or command line to get more detailed error messages.
For example, use /verbosity:detailed.
See http://msdn.microsoft.com/en-us/library/ms164311.aspx
Are you using Ninject?
If so, see this: http://groups.google.com/group/ninject/browse_thread/thread/1934e9260ba07ecd?pli=1 and this: http://www.techques.com/question/1-6173194/Strange-behaviour-when-using-Ninject-to-resolve-a-service-within-a-controller-factory
Are you using RavenDB?
If so, see this: http://groups.google.com/group/ravendb/browse_thread/thread/437738caf4760ce1/b7e92fd6cfeaaa17?#b7e92fd6cfeaaa17
In my case, I was seeing the message [AspNetCompiler] error ASPRUNTIME error message: Value cannot be null. in TeamCity.
In the full build logs, the more useful message at the bottom was:
error ASPRUNTIME : The pre-application start initialization method InitializePreStart on type MyApplication.MvcApplication threw an exception with the following error message: Value cannot be null.
As it turns out I had an exception being thrown by a method I had defined using PreApplicationStartMethod:
[assembly: System.Web.PreApplicationStartMethod(typeof(MyApp.MvcApplication), "InitializePreStart")]
namespace PrintFleet.PFE.RestService
{
public class MvcApplication : System.Web.HttpApplication
{
//....
public static void InitializePreStart()
{
// exception thrown here
}
}
}
The cause in my case was my prestart method was loading settings from the registry, and they didn't exist on the build server (but did on my machine, so it worked when I built it). I have no clue why webdeployment projects run this code.
I wrapped the entire thing in a try..catch that logs a fatal message (which in my app, goes to both the log file and windows event log). In builds, I don't really care if it fails since it doesn't need to do anything. In actual installations, if the settings are missing the app won't work (and so the log explains why).
Now, to the OP the problem seems to be in web activator. I would not be surprised if there is a method using webactivor in App_Start folder that is throwing the error, which is making it look like it's coming from WebActivator. Check there first, wrap things in try..catch if needed. It's also possible there is a bug in webactivator itself.
So because I came across this post while researching the problem, hopefully this information is useful to at least someone else.
TL;DR: Web deployment projects run the ApplicationPreStart methods when they compile. Ensure that you have try..catch blocks around any code run at prestart time or can otherwise handle the situation where the code is executed during compile time on your build server(s), outside of the IIS/hosting environment.

Resources