How to overcome the exception "The Type Initializer for "SAP.Middleware.Connector.RfcConfigParameters" threw an exception - Error#:-2146233036"

Babu picture Babu · Apr 25, 2013 · Viewed 8.1k times · Source

We have applications which is fetching data from SAP systems through DCOM SAP connector. Recently we have replaced with .NET connector. After deploying into production it worked for one day. Suddenly it is giving the specified error while accessing one RFC. The exception message is

The Type Initializer for "SAP.Middleware.Connector.RfcConfigParameters" threw an exception - Error#:-2146233036.

The code which we use create object for SAP.Middleware.Connector.RfcConfigParameters and use is below

string Value1 ="Val1";
string Value1 ="Val2";
string Value1 ="Val3";
string Value1 ="Val4";
string Value1 ="Val5";
string Value1 ="Val6";
string Value1 ="Val7";

RfcConfigParameters parms = new RfcConfigParameters();

parms.Add(RfcConfigParameters.Param1, Value1);
parms.Add(RfcConfigParameters.Param2, Value2);
parms.Add(RfcConfigParameters.Param3, Value3);
parms.Add(RfcConfigParameters.Param4, Value4);
parms.Add(RfcConfigParameters.Param5, Value5);
parms.Add(RfcConfigParameters.Param6, Value6);
parms.Add(RfcConfigParameters.Param7, Value7);

SapRfcDestination = RfcDestinationManager.GetDestination(parms);
RfcCustomDestination customDest = SapRfcDestination.CreateCustomDestination();
IRfcFunction func = customDest.Repository.CreateFunction("RFC_FUNCTION");

func.SetValue("DATA1", "VAL1")
func.SetValue("DATA2", "VAL2")
func.SetValue("DATA3", "VAL3")

RfcStructureMetadata metaData = customDest.Repository.GetStructureMetadata("STRUCTURENAME");
IRfcTable rfcTable = func.GetTable("TABLENAME");

We have traced the exception information and below is the exception information

System.TypeInitializationException: The type initializer for '<Module>' threw an exception. ---> <CrtImplementationDetails>.ModuleLoadException: The C++ module failed to load.
 ---> System.IO.FileLoadException: Could not load file or assembly 'msvcm80, Version=8.0.50727.6195, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
File name: 'msvcm80, Version=8.0.50727.6195, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.Runtime.InteropServices.COMException (0x8000FFFF): Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))
   at <CrtImplementationDetails>.DoDllLanguageSupportValidation()
   at <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* )
   at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )


   --- End of inner exception stack trace ---
   at <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException)
   at <CrtImplementationDetails>.ThrowModuleLoadException(String , Exception )
   at <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* )
   at .cctor()
   --- End of inner exception stack trace ---
   at SAP.Middleware.Connector.RfcConfigParameters..cctor()- Stack trace:   at SAP.Middleware.Connector.RfcConfigParameters..ctor()

Below are our observations
1. It is not throwing issue always. The issue is throwing intermittently.
2. When we go to the server machine and run the application there, it is not throwing error. The error is throwing only if the application access from other client machnies.
3. Same issue is not reproducible in dev, test and stage environments. It is issue in production alone 4. If we redeploy the specific dll it will start work without any error for one day or half day and next day onwards throw the error.

My specific questions are (1) How to overcome the exception which says "The Type Initializer for "SAP.Middleware.Connector.RfcConfigParameters" threw an exception - Error#:-2146233036"?
(2) Our primary suspect area is Memory leaks. Can we suspect any other areas?
(3) We have very limited to no access to production environment. So that we are trying to reproduce the issue in other servers in which we have full access like dev and test. We are considering multi user and multi login scenarios in order to reproduce the issue in other environments. Can we consider any other scenarios?

Update
We are managed to reproduced the issue in one of our test servers. And tried below things to resolve the issue. And installed Visual C++ 2005 Redistributable SP1, .NET connector 3.0 and VB6.0. Still issue is there. We are unable to found the root cause for the issue.

What else I can check and do in order to found root cause for the issue?

Edits based on response:
1. We are not using any static variables 2. We have installed Visual C++ 2005 Redistributable SP1.But still it didn't resolve the issue.

Answer

Mike Asdf picture Mike Asdf · May 3, 2013

This thread suggests that installing Visual C++ 2005 Redistributable SP1 package resolved it. (due to a dependency in sapnco_utils.dll)