NHibernate Validator throwing and catching sqillions of MappingExceptions (property not found) - nhibernate-validator

After upgrading from NHibernate 2 to 3.1, NHibernate Validator is throwing and catching tons of MappingExceptions with the message "property not found: myProp on entity MyEntity".
The stack trace is:
at NHibernate.Mapping.PersistentClass.GetProperty(String
propertyName, IEnumerable`1 iter) in
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\PersistentClass.cs:line
921 at NHibernate.Mapping.PersistentClass.GetProperty(String
propertyName) in
d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\PersistentClass.cs:line
934 at
NHibernate.Validator.Engine.ClassValidator.FindPropertyByName(PersistentClass
associatedClass, String propertyName)
The NHibernate Validator source code for the method FindPropertyByName doesn't look too hot - there's just a large chunk of commented out code.
Is this just because NHibernate Validator is not ready for NHibernate 3, or is there a workaround?

Related

'System.Reflection.TargetParameterCountException' while Invoking mailmessage mailwriter method

I am trying to create a SAVE Method for mailmessage, It is throwing the below error:
An unhandled exception of type 'System.Reflection.TargetParameterCountException' occurred in mscorlib.dll
Additional information: Parameter count mismatch.
Below is the Overriden Method:
_sendMethod.Invoke(
Message,
BindingFlags.Instance | BindingFlags.NonPublic,
null,
new object[] { _mailWriter, true },
null);
The extension method dosen't supports .NET framework 4.5 above versions.
So parameter count exceptions will occur.. The Same extension method is working fine in .NET Framework 4.0 below

Getting HazelcastSerializationException where ArrayDataSerializableFactory is not be able to create an instance for id

I am facing an issue when my web application is querying to Hazelcast cache to get data, HazelcastSerializationException is being thrown. We are using hazelcast-all-3.6.6.jar.
Following is stack trace for the same collected from server logs -
java.util.concurrent.ExecutionException: com.hazelcast.nio.serialization.HazelcastSerializationException: com.hazelcast.internal.serialization.impl.ArrayDataSerializableFactory#5e5caba is not be able to create an instance for id: 100 on
factoryId: -32
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponseOrThrowException(InvocationFuture.java:360) ~[hazelcast-all-3.6.6.jar!/:3.6.6]
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:225) ~[hazelcast-all-3.6.6.jar!/:3.6.6]
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:204) ~[hazelcast-all-3.6.6.jar!/:3.6.6]
at com.hazelcast.map.impl.query.MapQueryEngineImpl.addResultsOfPagingPredicate(MapQueryEngineImpl.java:503) ~[hazelcast-all-3.6.6.jar!/:3.6.6]
at com.hazelcast.map.impl.query.MapQueryEngineImpl.queryAllPartitionsWithPagingPredicate(MapQueryEngineImpl.java:388) ~[hazelcast-all-3.6.6.jar!/:3.6.6]
at com.hazelcast.map.impl.proxy.MapProxyImpl.values(MapProxyImpl.java:635) [hazelcast-all-3.6.6.jar!/:3.6.6]
This exception is in Hazelcast classes where, after getting QueryResultRow, It fails to do serialization. Following is code snippet for the same where it fails exactly:
QueryResultRow row = (QueryResultRow)i$1.next();
Object key = this.toObject(row.getKey());
Object value = this.toObject(row.getValue());
Following is implementation of toObject() method:
protected Object toObject(Object obj) {
return this.serializationService.toObject(obj);
}

Is there mongodb mapping converter for generic message

Is there mongodb mapping converter for generic message.
No argument constructor not available for generic message.
.11:47:30.937 [http-nio-9080-exec-1] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.messaging.MessageHandlingException: error occurred in message handler [messageHandler]; nested exception is org.springframework.data.mapping.model.MappingInstantiationException: Failed to instantiate org.springframework.messaging.support.GenericMessage using constructor NO_CONSTRUCTOR with arguments ] with root cause
java.lang.NoSuchMethodException: org.springframework.messaging.support.GenericMessage.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104)
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:61)
at org.springframework.data.convert.ClassGeneratingEntityInstantiator.createInstance(ClassGeneratingEntityInstantiator.java:83)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:251)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:231)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1186)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$200(MappingMongoConverter.java:78)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1134)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1097)
Also I am trying following config of mongotemplate
Please advise if correct
public MongoTemplate messagingMongoTemplate() throws Exception {
MongoTemplate mongoTemplate=null;
try {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
MappingContext mappingContext = new MongoMappingContext();
MappingMongoConverter mappingMongoConverter = new MappingMongoConverter(dbRefResolver,mappingContext);
CustomConversions customConversions = new CustomConversions(Arrays.asList(new MongoDbMessageBytesConverter()));
mappingMongoConverter.setCustomConversions(customConversions);
mongoTemplate=new MongoTemplate(mongoDbFactory,mappingMongoConverter);
Starting with version 3.0 it is recommended to use ConfigurableMongoDbMessageStore as that provides more options for customization, including a Converter for Message.
Out-of-the-box Spring Integration provides MongoDbMessageBytesConverter, which has become public since 4.2.10 and is used by default if there is no any external customization for the ConfigurableMongoDbMessageStore.

MethodAccessException when calling nlog LogManager.GetCurrentClassLogger()

I'm getting an exception when I run a unit test on a controller in web project (ASP.NET web api). The exception is thrown when LogManager.GetCurrentClassLogger() of the controller is executed:
System.MethodAccessException: Attempt by method 'Castle.Proxies.ClaimsPrincipalProxy.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' to access method 'Castle.DynamicProxy.Internal.TypeUtil.Sort(System.Reflection.MemberInfo[])' failed
It results in TypeInitializationException in LogManager.GetCurrentClassLogger().
here is the call stack:
at Castle.Proxies.ClaimsPrincipalProxy.GetObjectData(SerializationInfo, StreamingContext)
at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)
at System.AppDomain.get_Evidence()
at System.AppDomain.get_Evidence()
at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, ref String typeName)
at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord record)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, ref Object result, ref Object resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at NLog.Config.XmlLoggingConfiguration.get_AppConfig()
at NLog.LogFactory.get_Configuration()
at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
at NLog.LogFactory.GetLogger(String name)
at NLog.LogManager.GetCurrentClassLogger()
Update:
The issue happens when the unit test project references NSubstitute. So, it seems like there some dangerous combination of Web API, NSubstitute and NLog.
Update 2:
Found what upsets Nlog in Controller.
Before calling controller method I set mocked principal for Thread.CurrentPrincipal:
var principal = Substitute.For<ClaimsPrincipal>();
principal.Identity.Returns(...);
Thread.CurrentPrincipal = principal;
How could this be fixed?
The Castle assembly may be marked with the AllowPartiallyTrustedCallersAttribute, and that uses the level 2 security transparency model.
Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.
Can you try annotating your unit test (and Class) with the following attribute - [SecuritySafeCritical]

XmlJavaTypeAdapter throw user defined exception

Is there a way to throw user defined exception in XmlAdapter and catch them when JAXB marshalles/unmarshalls? I mean, I can throw my own exception but JAXB just ignores this exception and throws his own from which I can not get to my exception message or the exception object.
try {
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
jaxbUnmarshaller.unmarshal(inputStream);
}
catch (UserDefinedException e) {
// Do something.
}
Sorry for not posting the correct exception that JAXB throwed instead of mine. At this moment, I can not get to the code. Currentlly I am using JAXB-RI, but I used EclipseLink MoXY and encountered this problem.
I will post additional data when I am able to get the hand of the code. But till then, maybe someone knows what am I talking about. Some code example of correct usage of XmlAdapter is also great.
Thanks.
The expectation of a JAXB (JSR-222) implementation is that it throws a JAXBException. This means that any exceptions thrown within something like an XmlAdapter is going to end up getting wrapped. You could potentially use a stateful XmlAdapter to handle this use case:
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
MyXmlAdpater myXmlAdapter = new MyXmlAdapter();
jaxbUnmarshaller.setAdatper(myXmlAdapter);
jaxbUnmarshaller.unmarshal(inputStream);
if(myXmlAdapter.hasException() {
// Do something.
}
For an Example of using a stateful XmlAdapter see:
http://blog.bdoughan.com/2011/09/mixing-nesting-and-references-with.html

Resources