We are running into a very odd problem: We are using entity framework 4 and ria services for a silverlight 5 appliation hosted in IIS 6.1. For long periods of time, everything is running smoothly, but occasionally the application fails with the following error message in the event log:
WebHost failed to process a request.
Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/56703158
Exception: System.ServiceModel.ServiceActivationException: The service '/Services/EcoFleet-DomainServices-Repository-EcofleetRepository.svc' cannot be activated due to an exception during compilation.
The exception message is: The Entity 'DeviceData' in DomainService 'EcofleetRepository' does not have a key defined. Entity types exposed by DomainService operations must have at least one public property marked with the KeyAttribute.. ---> System.InvalidOperationException: The Entity 'DeviceData' in DomainService 'EcofleetRepository' does not have a key defined. Entity types exposed by DomainService operations must have at least one public property marked with the KeyAttribute.
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.ValidateEntityTypes()
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.Initialize()
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.CreateDescription(Type domainServiceType)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
at System.ServiceModel.DomainServices.Server.DomainServiceDescription.GetDescription(Type domainServiceType)
at System.ServiceModel.DomainServices.Hosting.DomainServiceHost..ctor(Type domainServiceType, Uri[] baseAddresses)
at System.ServiceModel.DomainServices.Hosting.DomainServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses)
at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity)
at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity)
--- End of inner exception stack trace ---
at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) Process Name: w3wp
Process ID: 2300
The application still responds, but no entities can be loaded from the server. After stopping and starting the site, everything works again.
The entity in this case (DeviceData) is a database table, and it does have a key, and regardless it seems to be random which entity fails. Furthermore I would only expect to see the "key not defined" error at compile time. Does anyone have a clue what the problem is, and how to fix it?
[Key]is really generating for item. I just uset4rarely. EDMX seems better for this kind of issues. - Davut Gürbüz