Geta / 404handler

The popular 404 handler for EPiServer, enabling better control over your 404 page in addition to allowing redirects for old urls that no longer works.
Apache License 2.0
54 stars 51 forks source link

Invalid cast exception #248

Open petrovicnemanja opened 1 year ago

petrovicnemanja commented 1 year ago

Any idea what can cause this exception?

2023-05-10 10:33:22,631 [1] ERROR BVNetwork.NotFound.Core.Data.DataAccessBaseEx: An error occureding in the ExecuteScalar method with the following sqlSELECT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = '404Handler.Redirects'. Exception:System.InvalidCastException: Specified cast is not valid. at BVNetwork.NotFound.Core.Data.DataAccessBaseEx.<>cDisplayClass6_0.b__0() 2023-05-10 10:33:22,693 [1] ERROR BVNetwork.NotFound.Core.Data.DataAccessBaseEx: An error occureding in the ExecuteSQL method with the following sqlCREATE TABLE [dbo].[404Handler.Redirects]( [Id] [uniqueidentifier] NOT NULL, [OldUrl] nvarchar NOT NULL, [NewUrl] nvarchar NOT NULL, [State] [int] NOT NULL, [WildCardSkipAppend] [bit] NOT NULL, CONSTRAINT [PK_404HandlerRedirects] PRIMARY KEY CLUSTERED ([Id] ASC) ON [PRIMARY] ) ON [PRIMARY]. Exception:System.Data.SqlClient.SqlException (0x80131904): There is already an object named '404Handler.Redirects' in the database. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at BVNetwork.NotFound.Core.Data.DataAccessBaseEx.<>cDisplayClass5_0.b__0() ClientConnectionId:fdcff185-5822-4a05-9579-904bbe4968f0 Error Number:2714,State:6,Class:16 ClientConnectionId before routing:de17607e-5d1f-4f3d-8d5b-1a44fe498b70 Routing Destination:cc9c0bbc1946.tr38524.westeurope1-a.worker.database.windows.net,11039 2023-05-10 10:33:22,769 [1] ERROR BVNetwork.NotFound.Core.Data.DataAccessBaseEx: An error occureding in the ExecuteScalar method with the following sqlSELECT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = '404Handler.Redirects'. Exception:System.InvalidCastException: Specified cast is not valid. at BVNetwork.NotFound.Core.Data.DataAccessBaseEx.<>c__DisplayClass6_0.b__0()

marisks commented 1 year ago

It seems that something was not initialized properly from the beginning. Is this a new project or an existing one? If new, you can delete all tables related to the 404 handler and stored procedure and try running again.

petrovicnemanja commented 1 year ago

It's an existing project. It happens during site initialization, can't put a figure on the date it started occurring, but I noticed it recently. The handler itself works, though, was just curious if it's any cause for concern or if there are any steps I can take to investigate, or if it's a known issue.

marisks commented 1 year ago

Ok. Then you should check if all tables and everything else exists and has the same columns as here: https://github.com/Geta/404handler/blob/master/src/Geta.404Handler/Core/Upgrade/Upgrader.cs

After that update version stored procedure to the latest version (if you have latest 404 handler) - 5 https://github.com/Geta/404handler/blob/717bac2ede30408240f5170ce8f17cddb2d28feb/src/Geta.404Handler/Core/Configuration/Configuration.cs#L31

petrovicnemanja commented 1 year ago

We are on BVN.404Handler 11.2.3, I will check if we can upgrade to the latest - 11.4.0 and Geta.404Handler 1.2.1.