Setup And Getting Started Forum


Getting Error - Please help me fix this to use mvccms - I am using vs2010 prof and sql 2008 r2

 
Server Error in '/' Application.
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 56: public IEnumerable<Portal> ListPortals()
Line 57: {
Line 58: return (from c in _entities.PortalSet
Line 59: .Include("DefaultLanguage")
Line 60: .Include("PortalResources")


Source File: C:\RkWork\Samples\mvccms-56618\MvcCms 2.0\MvcCms.Data\EntityPortalRepository.cs Line: 58

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
MvcCms.Data.EntityPortalRepository.ListPortals() in C:\RkWork\Samples\mvccms-56618\MvcCms 2.0\MvcCms.Data\EntityPortalRepository.cs:58
...admin edit for length

MvcCms.Web.Ioc.WindsorServiceLocator.DoGetInstance(Type serviceType, String key) in C:\RkWork\Samples\mvccms-56618\MvcCms 2.0\MvcCms.Web\MvcCms.Web\Ioc\WindsorServiceLocator.cs:35
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +76

[ActivationException: Activation error occured while trying to get instance of type ICmsService, key ""]
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +157
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance() +113
MvcCms.Web.Code.Routing.SetAppRoutes() in C:\RkWork\Samples\mvccms-56618\MvcCms 2.0\MvcCms.Web\MvcCms.Web\Code\Routing.cs:40
MvcCms.Web.MvcApplication.Application_Start() in C:\RkWork\Samples\mvccms-56618\MvcCms 2.0\MvcCms.Web\MvcCms.Web\Global.asax.cs:97
1 years 7 months 11 days ago by hellobrk

Replies

Reply posted by jon 1 years 7 months 11 days ago View Branch And Reply
That almost always means that the urlauthority record in your portals table is not matching up to the url you are opening the site with.

The project and database from source should be set to localhost:4342 in both the project local webserver startup and in the portals table.

Paste what you have in your portals table for urlauthority, I may need to commit the database again as I think someone may have checked in a different urlauthority value.
Reply posted by hellobrk 1 years 7 months 11 days ago View Branch And Reply
I am astonished at such a fast reply. Thank you very much. I have the following values in my Portals table

1 Default 11 Default localhost:4342 ...xxx
13 Real Pen 11 RealPen localhost:4342x ...xxx
14 RSC Consulting 11 rsc localhost:4342x ..xxx
15 Sandbox 11 sandbox localhost:4342x ...xxx

I have cutshort the columns after URL Authority column to make it more readable. Please let me know if you want any other details.

When I debug, the _entities is null , trying to figure out where it should be loaded to make sure it is not null.

Thank you very much once again.
Reply posted by jon 1 years 7 months 11 days ago View Branch And Reply
OK, that all looks right, what is the url in the browser when you get the error?

That doesn't sound right though that the _entities object is null, let me put a bad urlauthority value in my portals table and see if mine is null, don't think it should be.

Did you check your connection strings in web.config, that is another place you might be needing something. There are actually three connection strings, the standard one, the EF one, and the logging one, although not having the logging one set won't hurt anything.

The standard connection string is used by the membership provider so I imagine it is your EF string.

Quote: hellobrk
I am astonished at such a fast reply. Thank you very much. 

hehe, ya I have been checking the site often as I am patching things up from converting it to 2010 so I caught your question fast.
Reply posted by hellobrk 1 years 7 months 11 days ago View Branch And Reply
My browser url is

http://localhost:4342/

I initially changed two connection strings. My values are

<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=127.0.0.1;Initial Catalog=MvcCms;Persist Security Info=True;User ID=sa;Password=study"/>
<add name="MvcCmsEntities" connectionString="Data Source=127.0.0.1;Initial Catalog=MvcCms;Persist Security Info=True;User ID=sa;Password=study;MultipleActiveResultSets=True"/>
</connectionStrings>


As you said there will be three connection strings I searched and changed here also


<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=127.0.0.1;Initial Catalog=MvcCms;Persist Security Info=True;User ID=sa;Password=study" />
<commandText value="INSERT INTO Log (Date,Thread,Level,Logger,Message,Exception) VALUES (@logdate, @thread, @loglevel, @logger, @message, @exception)" />
<parameter>

Thanks a lot for fastest reply.
Reply posted by jon 1 years 7 months 11 days ago View Branch And Reply Answer
There is some stuff missing from your EF connection string, the metadata stuff has to be there.
    <add name="ApplicationServices" connectionString="Data Source=rsc1;Initial Catalog=MvcCms;Persist Security Info=True;User ID=rscsa;Password=password" providerName="System.Data.SqlClient" />
    <add name="MvcCmsEntities" connectionString="metadata=res://MvcCms.Data/MvcCmsDataModel.csdl|res://MvcCms.Data/MvcCmsDataModel.ssdl|res://MvcCms.Data/MvcCmsDataModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=rsc1;Initial Catalog=MvcCms;Persist Security Info=True;User ID=rscsa;Password=password;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

Try replacing what you have with those two and only change your password and data source, I assume you are not using sqlexpress?
  1 2