AutoMapper.Mapper.CreateMap "System.NullReferenceException: Object reference not set to an instance of an object. "Abnormal recurrence

Source: Internet
Author: User

Ⅰ. Problems arise

During the National Day holiday----October 5-------------found ", by parsing the exception stack information, the code appears in the Qrcodeservice Getqrcode method as follows the 8th line of code:

1 /// <summary>2 ///Scan code payment to get payment code3 /// </summary>4 /// <param name= "Reqmodel" ></param>5 /// <returns></returns>6  Publicresponsemodelbase Getqrcode (Qrcoderequestmodel reqmodel)7 {8Automapper.mapper.createmap<qrcoderequestmodel, qrcoderequestdto>();9     varReqdto = automapper.mapper.map<qrcoderequestdto>(Reqmodel);Ten     if(Reqdto.valid_minutes = =0) One     { AReqdto.valid_minutes = -;//The default setting is 20 minutes -     } -  the     if(string. IsNullOrEmpty (reqmodel.order_no)) -     { -         Throw NewResponseerrorexception ("No order ID obtained, please recheck order information"); -     } +     if(Reqmodel.pay_money <=0) -     { +         Throw NewResponseerrorexception ("The order price is incorrect, please re-verify the order"); A     } at     if(string. IsNullOrEmpty (reqmodel.goods_name)) -     ...... -     ...... -}

Exception Log:

1  ./Ten/5  -:Geneva: +[GETQRCODE_140340241_DCB85] Request Payment Center parameter: {"Biz_system":"5","Goods_name":"w17720171005140403733142/qdrpayment3577421317952512t/","merchant_id":"102573307097-102125439412","Notify_url":"Http://papi1.shenbianhui.cn//OrderPayBack/BackResult","Order_no":"DD2017100500470030","Order_time":"20171005140340","Pay_channel":" A","Pay_money":"30000","Remark":"","Return_url":"http://120.55.16.195/pay/returnYimeiCallBack.do"," Sign":"DE101B203758CBBE7F83CE04F20D6FB1","Third_pay_platform":" A","valid_minutes":"Ten"}2  ./Ten/5  -:Geneva: +[getqrcode_140340241_dcb85] Payment Center verification pass. 3  ./Ten/5  -:Geneva: +[getqrcode_140340241_dcb85] get QR code entry4  ./Ten/5  -:Geneva: +[getqrcode_140340241_dcb85] System exception: System.NullReferenceException: Object reference not set to an instance of an object. 5In automapper.typemapfactory.<>c__displayclass3_0.<mapdestinationpropertytosource>B__0 (imemberconfiguration _)6In System.linq.enumerable.any[tsource] (IEnumerable '1Source, Func '2predicate)7 in AutoMapper.TypeMapFactory.CreateTypeMap (Type sourcetype, type destinationtype, iprofileconfiguration options, Memberlist memberlist)8In automapper.configurationstore.<>c__displayclass80_0.<createtypemap>b__0 (typepair tp)9In System.Collections.Concurrent.ConcurrentDictionary '2. Getoradd (TKey key, Func '2valuefactory)Ten in Automapper.configurationstore.createmap[tsource,tdestination] (String profilename, Memberlist MemberList)  One in PaymentService.QRCodeService.GetQRCode (Qrcoderequestmodel Reqmodel) A in PaymentPlatform.QRCode.GetQRCode.MyBiz (String Requestjson) -In PaymentPlatform.QRCode.HandlerBase.ProcessRequest (HttpContext context)

From the 9th line there is concurrentdictionary, difficult to be caused by concurrency? At that time the system TPS was more than 50 concurrent.

The system has been running for several months and has never encountered such a problem before.

Further troubleshooting, after this exception occurs, all subsequent requests to this interface are processed to report this exception. In addition, of the three load nodes, only 9177 of the nodes reported the exception.

Intuition doubts, with the online one or two times a week, will not be 3 nodes AutoMapper.DLL version inconsistent. In order to minimize the impact, emergency contact operations, the 9177 node site files are deleted, copy from the other nodes to a copy. Operation and maintenance informed that the problem has not been reproduced after processing.

In the next few days, no similar incidents occurred on the line. I also think that is the issue of file version, it is no longer concerned.

Ⅱ. Abnormal recurrence

Who knows, in the last two days of the weekend, this anomaly appeared again, or appeared in the 9177 node.

That's not going to be understood. The file version should be the same.

Contact OPS quickly to help reclaim your site's application pool.

Who knows after the recovery, the problem remains.

Consulting operations, why only this node reported this exception, operation and maintenance disclosed October 5 did not copy the file, just restarted IIS.

That had to be emergency let OPS again restart IIS. The matter was temporarily settled.

Ⅲ. troubleshooting

In order to be able to stop the next weekend, decided to take this problem to a radical cure today.

As a preliminary analysis, AutoMapper.Mapper.CreateMap is a static method that may cause problems when multi-threading.

I've always known that AutoMapper recommends mapping relationships to be initialized at the start of a program, rather than initializing each time the object is converted.

I did not pay attention to this when I was using AutoMapper. It is written every time that you create a map and then convert the object.

The debt owed is always to be pay off. The system did not appear before such an exception, can only say that the time is not.

As Murphy's theorem says, what happens is always happening. This is no, not too late, on the national day and last weekend two holidays appeared.

Ⅳ. Abnormal re-disk

It is necessary to reproduce the anomaly. Of course, the small probability problem is not easy to measure out.

Fortunately, I have jmeter.

A new Automappertest.ashx file is created in the project, and the ProcessRequest method body is as follows:

 Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; Loghelperutil Loghelper=NewLoghelperutil ("", Logtype.hfagentpayservice); Loghelper.write ("[Automappertest]"); Thread.Sleep (NewRandom (). Next (1, -)); Try{Qrcoderequestmodel Reqmodel=NewQrcoderequestmodel (); AutoMapper.Mapper.CreateMap<qrcoderequestmodel, qrcoderequestdto>(); varReqdto = automapper.mapper.map<qrcoderequestdto>(Reqmodel); Thread.Sleep (NewRandom (). Next ( -, +)); Context.    Response.Write (Jsonconvert.serializeobject (reqdto)); }    Catch(Exception ex) {Loghelper.write ("[Automappertestexception]"+Ex.        ToString ()); Context. Response.Write (ex.    ToString ()); }}

Publish to a test environment.

Next, create a test plan for jmeter, simulating the number of 1000 threads to measure the ashx.

lasted for 20 minutes.

Process,

    • Re-overwrite the site's files, the AUTOMAPPER.MAPPER.CREATEMAP statement appears the following exception, at 11:08:08 this second appeared 160 times.
2017/10/17 11:08:08[automappertestexception]system.invalidoperationexception: The collection has been modified or the enumeration operation may not be performed.   in System.Collections.Generic.List ' 1.enumerator.movenextrare ()   in System.linq.enumerable.any[tsource] ( IEnumerable ' 1 source, Func ' 2 predicate)   in AutoMapper.TypeMapFactory.CreateTypeMap (type sourcetype, type destinationtype, iprofileconfiguration options, Memberlist memberlist)   in automapper.configurationstore.<> C__DISPLAYCLASS80_0.<CREATETYPEMAP>B__0 (typepair tp)   in System.Collections.Concurrent.ConcurrentDictionary ' 2.GetOrAdd (TKey key, Func ' 2 valuefactory)   in Automapper.configurationstore.createmap[tsource,tdestination] (String profilename, memberlist MemberList)   in PaymentPlatform.Test.AutoMapperTest.ProcessRequest (HttpContext context)

    • At noon to find operations to manually recycle the application pool, the AUTOMAPPER.MAPPER.CREATEMAP statement has the following exception, and the exception of the holidays. This anomaly occurred 43,351 times between 12:02:04~12:03:17.
2017/10/17 12:02:04[automappertestexception]system.nullreferenceexception: Object reference not set to an instance of an object.   in Automapper.typemapfactory.<>c__displayclass3_0.<mapdestinationpropertytosource>b__0 ( Imemberconfiguration _)   in System.linq.enumerable.any[tsource] (IEnumerable ' 1 source, Func ' 2 predicate)   in AutoMapper.TypeMapFactory.CreateTypeMap (Type sourcetype, type destinationtype, iprofileconfiguration options, Memberlist memberlist)   in Automapper.configurationstore.<>c__displayclass80_0.<createtypemap>b__0 (Typepair TP)   At System.Collections.Concurrent.ConcurrentDictionary ' 2.GetOrAdd (TKey key, Func ' 2 valuefactory)   in Automapper.configurationstore.createmap[tsource,tdestination] (String profilename, memberlist MemberList)   in PaymentPlatform.Test.AutoMapperTest.ProcessRequest (HttpContext context)

Paste the jmeter pressure test:

AutoMapper.Mapper.CreateMap System.NullReferenceException: Object reference not set to an instance of an object. "Abnormal recurrence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.