showing exception on declaring new data member in class file using petapoco data access framework - petapoco

I am using petapoco dataaccess framework, after declaring one new parameter in class file according to database table i am getting the exception below mentioned, in windows service at starting the service.
Service cannot be started. System.MissingMethodException: Method not found: 'System.String projectname.Models.EmailTemplatePOCO.get_Subject()'.
at EmailService.EmailService.StartEmailService()
at EmailService.EmailService.ScheduledService() in d:\Project\Projectname\trunk\projectname\EmailService\EmailService.cs:line 85
at EmailService.EmailService.OnStart(String[] args) in d:\Project\projectname\trunk\projectname\EmailService\EmailService.cs:line 66
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

Does your poco use properties? It will need to eg;
public string Subject {get; set;}
Not sure if you're getting a petapoco error or not

Related

The server encountered an error processing the request. See server logs for more details

I have a simple problem.
I've created a WCF Data Service 5.6 in visual studio 2013, and in its *.svc.cs file, modified line
public class CustomdataService : DataService< /* TODO: put your data source class name here */ >
to connect my entities
public class CustomdataService : DataService< SchedulerEntities >
But when I want to see the service in browser it gives me following error
Request Error
The server encountered an error processing the request. See server logs for more details.
The entity framework is nothing but a single table...
The actual error can be different. In my case I got the same general error message when starting with AdventureWorks2012 database.
So the actual problem can be seen by appending an attribute to the service class as described at here:
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class WcfDataServiceAW : EntityFrameworkDataService<AdventureWorks2012Entities> { ... }
Hope it helps someone.
PS. My error is:
The exception message is 'The property 'SpatialLocation' on type 'Address' is of type 'Geography' which is not a supported primitive type.'.
It seems that Entity Framework 6 and WCF Data Services 5.6.0 need some provider to work together, read more on Using WCF Data Services 5.6.0 with Entity Framework 6+.
You can download the provider simply by using NuGet Package Console Manager:
Install-Package Microsoft.OData.EntityFrameworkProvider -Pre
Its version is alpha 2, so in future, search for final release. it worked for me however.
Final thing is, instead of using DataService<T>, you need to use EntityFrameworkDataService<T>. T is the name of your entities.
According to this post, you have to change inherited type of CustomdataService.
Replace the base type of your DataService. For EF 5 or below, your data service should inherit from DataService where T is a DbContext or ObjectContext. For EF 6 or greater, your data service should inherit from EntityFrameworkDataService where T is a DbContext. See What’s the difference between DataService and EntityFrameworkDataService below for more details.
go to edmx, in the diagram, remove all the tables until the only one you want is remain,
then should be okay, cannot have all the tables, this is what I found,
KT Wong

System.Security.HostProtectionException when calling webservice from with a function

I'm getting the following error when calling a webservice from a function.
I have referenced all the required assemblies in sql server with "unsafe" permission set and have registered the project assembly with "external access" and the serializer assembly with "safe" permission sets. I have also looked into the code and I don't see anything like message popup etc...that would be irrelevant in sql server's context. I have created another console app that uses the same service and it can access the service just fine from the same server. What else could be causing this issue? Any help is appreciated.
Error: System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host. at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) at System.ServiceModel.ChannelFactory1.CreateDescription() at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) at System.ServiceModel.ChannelFactory1..ctor(Binding binding, EndpointAddress remoteAddress) at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress) at MWMInterfaceBeanServiceClient.MWMInterfaceBeanServiceClient..ctor(Binding binding, EndpointAddress remoteAddress) at MWMInterfaceBeanServiceClient.MWMServiceClient.GetClient() at MWMInterfaceBeanServiceClient.MWMServiceClient.UpdateMobileCrew(Boolean active, Boolean available, Boolean availForOp, String contract, String code, String name, Int32 number, String crewCenter, String crewGroup, String crewId, Int32 crewSize, String crewSupervisor, String crewType, Boolean mdtCrew, SqlXml members, String district, String division, String serviceArea, String mobileNum, String pagerNum, Boolean tempFlag, SqlXml vehicles) The protected resources (only available with full trust) were: All The demanded resources were: Synchronization, ExternalThreading
so, I marked the assemblies as UNSAFE and that made this error go away but gave me another error that said it wasn't able to serialize one of the proxies generated by svcutil to make the request. I already had the serializer assembly generated using sgen in a post build task and registered as UNSAFE and it seems that didn't work. Maybe this only works for simple methods with native types? Therefore, I resorted to a different method mentioned in the following link.
http://www.vishalseth.com/post/2009/12/22/Call-a-webservice-from-TSQL-(Stored-Procedure)-using-MSXML.aspx

WCF Data Services error "The given name 'Foo' was not found in the entity sets"

I'm developing a WCF Data Service to expose a database. I want to provide access to one of the tables (call it 'Foo'), so I put this in the InitializeService method of my DatabaseService.svc.cs:
config.SetEntitySetAccessRule("Foo", EntitySetRights.AllRead);
However, when the service is initialized it throws an ArgumentException with the message "The given name 'Foo' was not found in the entity sets."
The table is definitely in the .edmx file with that name, case and spelling correct. It's also in the .Designer.cs file, like this:
[EdmEntityTypeAttribute(NamespaceName="FooDBModel", Name="Foo")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class Foo : EntityObject
The service class itself is declared as:
public class FooDatabaseService : DataService<FooDBEntities>
Have you tried using the fully qualified name?

nHibernate: Unable to locate persister

Running VS2003, nHB 3.0.0.3001, trying to run a unit test through Gallio 3.2. The code is from the first session of "Summer of nHibernate". I am getting the following error when attempting to run the test.
NHibernate.HibernateException: Unable to locate persister: DataTransfer.Customer
TargetSite: Void OnLoad(NHibernate.Event.LoadEvent, NHibernate.Event.LoadType)
HelpLink: null
at NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType)
at NHibernate.Impl.SessionImpl.Get(String entityName, Object id)
at NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id)
at NHibernate.Impl.SessionImpl.Get[T](Object id)
at DataAccessLayer.NhibernateDataProvider.GetCustomerById(Int32 customerId)
My very uneducated guess is that the Customer class cannot be seen. But both the unit test and the data access layers have a reference to the DataTransfer assembly that holds the Customer class. The Customer class is public and all the properties are public virtual.
The nHB config file is in the directory, and the Customer mapping file is an embedded resource. Seems to fail on the
line:
return session.Get<Customer>(customerId);
Make sure your mapping file is named *.hbm.xml
Make sure it is set to an embedded resource.
If these fail, debug and when it fails, catch the exception and look at the InnerException - NHibernate has fantastic error messaging hidden in there.
Hope those thigs help out - otherwise we can look into some other options (but 1 and 2 solve 90% of persister problems)
I'm using ActiveRecord for entity mapping, got the same error when tried to use ISession.Get,
instead of using configuration for retrieving session, like this:
ISession session = new NHibernate.Cfg.Configuration()
.Configure()
.AddAssembly(typeof(Account).Assembly)
.SetInterceptor(new SqlStatementInterceptor())
.BuildSessionFactory().OpenSession();
I changed it to work through ActiveRecordMediator:
ISession session = Castle.ActiveRecord.ActiveRecordMediator
.GetSessionFactoryHolder().
CreateSession(typeof(Castle.ActiveRecord.ActiveRecordBase));
now its working great..
On your hibernate.cfg.xml file, add this code:
<mapping assembly="(name of your Assembly Project)" />
Basically, on your code its:
<mapping assembly="DataTransfer" />

Adding field to WCF data contract breaks clients?

I have a WCF service that returns a class that implements IExtensibleDataObject. I need to add a new field to this class. I updated the DataContract interface and made the change to the class. Now when I try to run my client application I get the following error:
Could not load file or assembly
'xxx.yyyy.zzzz, Version=1.3.9.26111,
Culture=neutral,
PublicKeyToken=b09e2f3e9b5894f0' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
The AssemblyVersion of the WFC class has been changed - does that break client?
EDIT:
There are clients in production that use this service. I do not want to make them update their service reference and redeploy their clients for this simple change if possible.
It depends on how you have set up your data contract.
In WCF, using all the defaults, your service will use the DataContractSerializer (DCS) to serialize your object into XML. The DCS will serialize your fields in order - first the public ones, then the private ones. Within each visibility group, it will order the fields/properties alphabetically by name.
Thus, if you introduce a new public property MiddleName and you already had FirstName and LastName, you would be fine: the old XML would have been
<YourObject>
....
<FirstName>.....</FirstName>
<LastName>.....</LastName>
</YourObject>
and your new one would just simply add a new property at the end:
<YourObject>
....
<FirstName>.....</FirstName>
<LastName>.....</LastName>
<MiddleName>....</MiddleName>
</YourObject>
Such an update "add something at the end" should work just fine, the DCS will just simply ignore additional tags in the XML.
However: had you introduced a property called Gender, that would be stuck between <FirstName> and <LastName> and would thus break the order of the data in your XML and thus would break the data contract - no "old" client will be able to call your new service.
In order to take control of this, you can put specific Order= attributes on your data members in your data contract:
[DataContract]
public class SomeAddress
{
[DataMember(Order=0)]
public string FirstName;
[DataMember(Order=1)]
public string LastName;
}
Then you could easily add a new property - just add it to the end of the list!
[DataContract]
public class SomeAddress
{
[DataMember(Order=0)]
public string FirstName;
[DataMember(Order=1)]
public string LastName;
[DataMember(Order=2)]
public string Gender;
}
So by using the Order= attribute on your data contracts, you can take control of your XML layout, and you can make simple extensions of existing data contracts non-breaking updates.
For more background and in-depth know-how, you ought to read Serialization in Windows Communication Foundation on MSDN Magazine's web site - highly recommended.
From your service reference context menu choose... "Update Service Reference"