Invalid Cast Exception at startup

Jan 22, 2009 at 2:26 AM
Hi,
Firstly, thank you for what looks like is going to be a great starting resource.

I have managed to get everything installed and performed the configurations as set out in the install notes.  However, when I try to run this inside of VS2008, i get the following error:


System.InvalidCastException was unhandled by user code
  Message="Unable to cast object of type 'Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry' to type 'Kigg.Infrastructure.EnterpriseLibrary.WeblogEntry'."
  Source="Kigg.Infrastructure.EnterpriseLibrary"
  StackTrace:
       at Kigg.Infrastructure.EnterpriseLibrary.WeblogTraceTextFormatter.<GetExtraTokenHandlers>b__0(LogEntry le) in C:\Documents and Settings\Chris Ledden\My Documents\Visual Studio 2008\Projects\Kigg\EnterpriseLibrary\Logging\WeblogTraceTextFormatter.cs:line 29
       at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.GenericTextFormatter`1.Format(T instance, StringBuilder output)
       at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter.Format(LogEntry log)
       at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
       at Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener.TraceData(TraceEventCache eventCache, String source, TraceEventType eventType, Int32 id, Object data)
       at Microsoft.Practices.EnterpriseLibrary.Logging.LogSource.TraceData(TraceEventType eventType, Int32 id, LogEntry logEntry, TraceListenerFilter traceListenerFilter)
       at Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter.ProcessLog(LogEntry log)
  InnerException: 


I have set up the virtual directory in IIS, and also set Kigg.web as the startup project, and set a default document in iis of default.aspx.

Is there anything else I need to do to get this running?

Thanks

Chris
Coordinator
Jan 22, 2009 at 4:14 AM
Are your sure you are using the same Enterprise library that is attached with the source code? References\EntLib?
Jan 22, 2009 at 4:32 AM
Hi, thank you for the quick response.

Actually I haven't downloaded or installed any  of the Enterprise Library.  Is that a pre-requisite?

Thanks again.

Chris
Coordinator
Jan 22, 2009 at 11:56 AM
Hi, could pls send me the web.config to kazimanzurrashid at gmail dot com. So that I can take a look.
Jan 22, 2009 at 1:39 PM
I got exactly the same thing.  It was triggered by an incorrect db connection string for my system (I'm not using SQL Express).

I've got past it and now I'm seeing 'Story does not exists.'
Coordinator
Jan 22, 2009 at 1:57 PM
Hi,

If you seeing the Story does not exists message that means you have configured it properly. Yes the database comes with empty story.
Jan 22, 2009 at 6:41 PM
I have emailed the web.config to you.  let me know what you find..

On the Story Does Not Exist part, do you mean that we need to add a default story to the db initially?

Chris
Jan 22, 2009 at 9:17 PM
Does this app include member administration?

Sent from my iPhone

On Jan 22, 2009, at 8:57 AM, kazimanzurrashid <notifications@codeplex.com> wrote:

From: kazimanzurrashid

Hi,

If you seeing the Story does not exists message that means you have configured it properly. Yes the database comes with empty story.
Coordinator
Jan 23, 2009 at 3:00 AM
@Leddo:
Yes I just checked the file and it is perfectly okay, can you pls make sure that Web bin directory has the dlls of EntLib from References/EntLib. Once you are able to run it you can use the Submit page to add story.
Coordinator
Jan 23, 2009 at 3:05 AM
@joomp:

It has 3 kinds of role:
  • Public User
  • Moderator
  • Administrator
Depending upon the role, there certain functionality that are available like e.g Edit Story, Delete Story, Confirm Story As Spam, Approve Story, Mark Comment As Offended, Lock/Unlock User, Block User IP Address, Publish Story etc

Hope this help.
Jan 23, 2009 at 5:18 AM
Hi Kazimanzurrashid,
I copied the dll's as suggested, and still get the same issue. Could it be something to do with the way I have the the local host set up or permissions or soemthing like that?

Thanks for your help.

Chris
Jan 23, 2009 at 5:23 AM
Edited Jan 23, 2009 at 5:31 AM
Actually something interested just happened.  When I stopped the debugger, I noticed the IE page did something then showed the following error:

Server Error in '/Kigg' Application.

Login failed for user 'CHRIS_LAPTOP\ASPNET'.

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.Data.SqlClient.SqlException: Login failed for user 'CHRIS_LAPTOP\ASPNET'.

Source Error: 

Line 11:         public static void OnStart()Line 12:         {Line 13:             Bootstrapper.Run();Line 14:             Log.Info("Application Started");Line 15:         }

Source File: C:\Documents and Settings\Chris Ledden\My Documents\Visual Studio 2008\Projects\Kigg\Web\Global.asax.cs    Line: 13 

Stack Trace: 

[SqlException (0x80131904): Login failed for user 'CHRIS_LAPTOP\ASPNET'.]   
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844759   
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194   
...
...
   Kigg.Web.GlobalApplication.Application_Start() in C:\Documents and Settings\Chris Ledden\My Documents\Visual Studio 2008\Projects\Kigg\Web\Global.asax.cs:39


Maybe there something wrong with the virtual URL...


Coordinator
Jan 23, 2009 at 5:28 AM
Okay this is the issue with your machine configuration, ensure that CHRIS_LAPTOP\ASPNET has the permission to access SQL Server or try to login with sa.
Jan 23, 2009 at 7:45 PM
Hi,
I'm am progressing, but still not there yet...

Now I get:
Line 4:      HttpContext.Current.RewritePath(Request.ApplicationPath);Line 5:      IHttpHandler httpHandler = new MvcHttpHandler();Line 6:      httpHandler.ProcessRequest(HttpContext.Current);Line 7:  %>

Source File: c:\Documents and Settings\Chris Ledden\my documents\visual studio 2008\projects\kigg\web\Default.aspx    Line: 
System.Web.HttpException was unhandled by user code
  Message="The incoming request does not match any route."
  Source="System.Web.Routing"
  ErrorCode=-2147467259
  StackTrace:
       at System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext)
       at System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext)
       at System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
       at ASP.default_aspx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\Documents and Settings\Chris Ledden\my documents\visual studio 2008\projects\kigg\web\Default.aspx:line 6
       at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
       at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
       at System.Web.UI.Page.Render(HtmlTextWriter writer)
       at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
       at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

Feb 2, 2009 at 7:25 PM
Leddo, did you figure out your last issue?  I am having the same issue as well.
Feb 2, 2009 at 10:39 PM
I ended up just using the standard database in the App_Data directory and it worked.
Apr 2, 2009 at 1:44 PM
Edited Apr 2, 2009 at 2:11 PM
I just upgraded www.pimpthisblog.com to 2.1 and I have now having the same issue.
I tried to debug the app and found that the issue appears only when the spamcheck kicks in. For example, if submit a story with a user that has submit more than 3 stories the error does not occur while it does with a new user.

I still have not figured out a solution, but wander if any of you might have found a fix for this.

BTW, in my case I do not think it has anything to do with the Db Connection, since everything else works.

Thanks.

Here is the stack trace:

Type : System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : Kigg.Core
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : Void Process(System.String, Boolean, System.String, Kigg.DomainObjects.IStory)
Stack Trace :    at Kigg.Infrastructure.SpamPostprocessor.Process(String source, Boolean isSpam, String storyUrl, IStory story)
   at Kigg.Service.StoryService.<>c__DisplayClass6.<Create>b__4(String source, Boolean isSpam)
   at Kigg.Infrastructure.DefaultSpamProtection.<>c__DisplayClass6.<IsSpam>b__0(String response)
   at Kigg.Infrastructure.CachingHttpForm.GetAsync(String url, Action`1 onComplete, Action`1 onError)
   at Kigg.Infrastructure.DefaultSpamProtection.IsSpam(SpamCheckContent spamCheckContent, Action`2 callback)
   at Kigg.Service.StoryService.Create(IUser byUser, String url, String title, String category, String description, String tags, String userIPAddress, String userAgent, String urlReferer, NameValueCollection serverVariables, Func`2 buildDetailUrl)
   at Kigg.Web.StoryController.Submit(String url, String title, String category, String description, String tags)
Apr 2, 2009 at 2:55 PM
Based on this thread: http://kigg.codeplex.com/Thread/View.aspx?ThreadId=45152
I added the following check on line # 37 of \KiGG-v2.1\Core\Infrastructure\Spam\SpamPostprocessor.cs

if (approvingStory != null) {
    approvingStory.Approve(SystemTime.Now()); }
This seems to have resolved the issue, although I am not entirely sure yet of the repercusssions. I will post more if I find that this causes different issues.

Cheers,
Coordinator
Apr 7, 2009 at 5:34 PM
antoniochagoury, I have fixed the issues, it was throwing exception due to the multi-threading, check the latest version.