Create a small project these days-use the Windows service to call the sap interface to obtain data. Baidu on the internet, determined the solution-use sap. Net connector 3.0 to interact with the SAP system. Using win7 ultimate and Visual Studio 2010 ultimate -- so I wanted to use. NET Framework 4.0 -- so I had the annoying exception later ~~~ (Sometimes the risk of using the latest things is not small ).
I wrote the business logic for interacting with the sap interface in a class library project, and generated the DLL for Windows service to call. After I install the service, I view the output trace log and see the exception information-type Initial Value Setting item of "sap. Middleware. connector. rfcdestinationmanager", which causes an exception. Tat ~~
1 /// <summary>
2 // obtain the RFC connection target
3 /// </Summary>
4 private rfcdestination getdestination ()
5 {
6 try
7 {
8 var destinationname = "lgdderp"; // SAP system ID
9 idestinationconfiguration destinationconfiguration = new sapconfiguration ();
10 rfcdestinationmanager. registerdestinationconfiguration (destinationconfiguration );//This raises the annoying exception ~
11/* return the target object with the specified name. Rfcdestinationmanager checks whether the target object has been created. If not, it requests necessary login parameters from the configuration object and creates the target object. If the configuration object is not registered by the application, an exception is thrown. */
12 rfcdestination = rfcdestinationmanager. getdestination (destinationname );//
13 rfcdestinationmanager. unregisterdestinationconfiguration (destinationconfiguration );
14 return rfcdestination;
15}
16 catch (exception ex)
17 {
18 logger. Log ("exception occurred when obtaining the sap connection target:" + ex. Message );
19 return NULL;
20}
21}
So I created a test project and used the test project in vs (it seems that we want to install resharper 6.0 ~) To call the DLL. Hey, it can run normally, but an exception is thrown when you use winform to call it! Debug the code and run to the 10th lines of the code shown above. An exception occurs ~~...... Later, I checked the innerexception information in the exception-"The hybrid mode assembly is generated for the runtime version of" v2.0.50727 ". Without other information configured, the Assembly cannot be loaded in the 4.0 runtime ". OMG and inspiration have finally emerged. It may be a problem with runtime version compatibility. So Baidu -- [http://blog.163.com/gz_ricky/blog/static/182049118201011104242527/]. After modification, it will be okay in winform. However! But the exception is still reported in the Windows Service-although I have modified the app. config file in the service project! Okay, change to the FR version -- change to 3.5 ~...... After modification, install and view the output log -- OK! Okay.