Recently, when using NHibernate, we encountered a very strange problem. When calling Session.SaveOrUpdate () method, an exception was thrown.
Look at the screenshot below. Although this exception was caught by vs in the catch line, the real problem is inside the try code block. As for how to make vs catch and prompt when problems occur, there is a detailed introduction in my other blog articles. I won’t talk about it here.
The code to throw an exception is as follows:
In the end, it’s the call Session.SaveOrUpdate The exception thrown when (). And I’ll go to the details of exception to see if there are any hints, but there are no valuable clues such as innerexcitation and message. Later, I kept thinking about why there was a problem, and finally found the root of the problem, which is current_ session_ context_ There’s something wrong with class.
The scene is like this. My project is a web project, in which NHibernate is used, and then I write the configuration in the web.config In the middle. After that, I wrote some new methods, and then set up a unittest project. Later, I need to move all the content related to NHibernate in order to test these service methods. I’ll take it web.config The content in is copied to the app.config The session context in NHibernate is still web, which is the reason for the problem.
Then I changed it to thread_ Static, the problem is solved. The reason is that the project of unittest does not have IIS. If session is still obtained from the web at this time, it will be null, so an exception is thrown.
- A first chance exception of type ‘ System.NullReferenceException ‘when occurred, you did encounter a bug
- Invalid object name ‘UserInfo’
- Exception ignored in: bound method basesession__ del__ Of
- 0xc015000f: the activation context being deactivated is not recently activated
- Springboot + mybatis plus transaction management
- tensorflow.python.framework.errors_impl.InternalError: Failed to create session.
- Tensorflow training could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR error
- Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details
- [Python] notimplemented and notimplemented error
- C ා imitate on error resume next in VB
- The provider is not compatible with the version of Oracle client systems
- Multiple exceptions are caught in a single catch block
- Unable to read Scheme Document ‘ http://www.springframework.org/schema/beans/spring-beans-4.1.xsd ‘ [How to Fix]
- soapUI Error Loading WSDL
- Tensorflow with tf.Session The usage of () as sess
- Servlet.service() for servlet [dispatcherServlet] in context with path  threw exception [Request p
- The problem of [connection lost contact] after C # code connecting Oracle database for a period of time
- there was an error running the selected code generator unable to retrieve metadata for
- IOS app connect error store submitted for review
- Vue error: no postcss config found solution