12 Replies Latest reply: Oct 24, 2011 5:33 PM by Christian Wagner RSS

Exception .Net Connector 3.0 when used in custom wep part

Martijn van den Meijdenberg
Currently Being Moderated

Hi,

 

I'm trying to develop a custom web part for SharePoint 2007. The web part is containing a user control that has a button.

When clicking the button some data needs to be read from SAP using the .NET connector 3.0.

 

Everything works fine when I use the user control in an ordinary web application. But when trying to use it in a custom web part the following exception is thrown bij the Invoke function of the .NET Connector:

The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception.

 

This exception has an inner exception with the following text:

Event handlers can only be bound to HttpApplication events during IHttpModule initialization.

 

The stack trace looks like:

at SAP.Middleware.Connector.RfcSessionManager.GetConnection(RfcDestination dest)

at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination)

at ...

 

Does anyone have a suggestion? I'm really stuck with this.

 

 

Kind regards,

Martijn

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Martijn van den Meijdenberg
    Currently Being Moderated

    Has anyone used the .NET Connector 3.0 within a custom SharePoint web part already?

    I still haven't been able to fix the problem yet.

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Martijn van den Meijdenberg
    Currently Being Moderated

    In the meanwhile I discovered that the .NET Connector 3.0 does not work within a Web Service as well.

    Here's a thread from another forum where somebody has the same problem:

     

    http://sapboard.ru/forum/viewtopic.php?p=429666

     

    No solution there as well.

     

    This is the stacktrace after the exception that occurs when i try to invoke a web service operation that internally works with .NET Connector:

    System.TypeInitializationException: The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception. ---> System.InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.

       at System.Web.HttpApplication.ThrowIfEventBindingDisallowed()

       at System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification)

       at SAP.Middleware.Connector.RfcWebSessionProvider..ctor()

       at SAP.Middleware.Connector.RfcSessionManager..cctor()

       --- End of inner exception stack trace ---

       at SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(Object state)

       at System.Threading._TimerCallback.TimerCallback_Context(Object state)

       at System.Threading.ExecutionContext.runTryCode(Object userData)

       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)

       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

       at SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination)

       at MyClass.MyMethod(string text)

     

    By the way, it works when running from the debugger. But same exception occurs as in the web part when I host the web service on a web server.

     

    Could somebody perhaps shine some light on this?

    The .NET Connector 3.0 seems to work with some kind of mechanism that doesn't fit within a Web Service and Web Part (and perhaps other techniques as well...)

     

    Or could this be a bug?

     

    Edited by: Martijn van den Meijdenberg on Sep 8, 2011 9:55 AM

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Stefan Hansen
    Currently Being Moderated

    I'm experiencing the exact same problem...

     

    Running the code from a console application doesn't produce the exception, but that doesn't help us when we want to run it through a web service.

     

    Best Regards,

    Stefan Hansen

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Martijn van den Meijdenberg
    Currently Being Moderated

    Thanks for your answer.

    I'm now looking in the direction of IIS 7 configuration and/or the configuration of my web service web.config.

     

    Try googling for "IIS7 Event handlers can only be bound to HttpApplication events during IHttpModule initialization"

     

    I read a suggestion to run the application in classic mode instead of integrated mode. Tried that but it resulted in the application failing to start. I'm looking further into that at the moment

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Martijn van den Meijdenberg
    Currently Being Moderated

    I managed to fix the problem with the web service.

    Solution for me was to create a new empty web site with target framework 4.0. (My old one was 3.5)

    This results in an almost empty web.config in opposite to a 3.5 web site.

     

    Unfortunately for the web part this will not be a solution because a custom share point web part must target the 3.5 version of .NET. But I'm sure the solution there must have something to do with configurations of IIS and my own web.config

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Christian Wagner
    Currently Being Moderated

    I was facing the same issue with the latest version, you can use one version earlier (3.0.3 start to create issues).

     

    Regards,

    Christian

    • Re: Exception .Net Connector 3.0 when used in custom wep part
      knr1021 kim
      Currently Being Moderated

      I faced with Same issue. Please help me.

       

      I'm developing program Calling SAP RFC function by SAP .NET Connector 3.0 (Nco3.0)

       

      I complete the programe in my computer ( window XP(x86), .NET Framework3.5, .NET Connector 3.0(x86) , visual studio 2005)

      rfcfunction I wanted is called very well.  This is not web service.

       

      But, After apply the source to another Server , The programe is not running. (Windows server 2008(x64), .NET Framework3.5, .NET Connector(x64))

      This is webservice.

       

      I changed App.config file to web.config file. and I made Required Libraris locate  under the [bin] directory.

       

      what it means that " The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception"

      I don't know about that.....

       

       

      Exception is generated at this point . it means Make the remote call

      rfcFunction.Invoke(destination);

       

      There are some Errrors....

       

       

      [InvalidOperationException: Event handlers can only be bound to HttpApplication events during IHttpModule initialization.]

         System.Web.HttpApplication.ThrowIfEventBindingDisallowed() +11182675

         System.Web.HttpApplication.AddSyncEventHookup(Object key, Delegate handler, RequestNotification notification, Boolean isPostNotification) +30

         System.Web.HttpApplication.add_EndRequest(EventHandler value) +62

         SAP.Middleware.Connector.RfcWebSessionProvider..ctor() +260

         SAP.Middleware.Connector.RfcSessionManager..cctor() +266

       

      [TypeInitializationException: 'The type initializer for 'SAP.Middleware.Connector.RfcSessionManager' threw an exception]

         SAP.Middleware.Connector.RfcSessionManager.UpdateSessions(Object state) +0

         System.Threading.ExecutionContext.runTryCode(Object userData) +376

         System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) +0

         System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +98

         SAP.Middleware.Connector.RfcFunction.Invoke(RfcDestination destination) +1808

         MultiLoginTest.ExampleSimpleCall(String ERPID, String targetURL) in d:\NETS\SSO\SAPLogonAgent\MultiLoginTest.aspx.cs:243

         MultiLoginTest.Page_Load(Object sender, EventArgs e) in d:\NETS\SSO\SAPLogonAgent\MultiLoginTest.aspx.cs:130

         System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25

         System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42

         System.Web.UI.Control.OnLoad(EventArgs e) +132

         System.Web.UI.Control.LoadRecursive() +66

         System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

       

      Edited by: NaRaeeee on Oct 28, 2011 7:34 AM

       

      Edited by: NaRaeeee on Oct 28, 2011 7:37 AM

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Kevin Knapp
    Currently Being Moderated

    We had many similar issues directly using NCo 3.0 from the SharePoint 2010 deployed web part, so we now always put our NCo SAP access in a WCF service (deployed to IIS App Fabirc .Net 4.0) and have the web part call the WCF service.  This avoids all the SharePoint related issues.

  • Re: Exception .Net Connector 3.0 when used in custom wep part
    Kuldeep Patel
    Currently Being Moderated

    Did anyone found solution to the following error "The type initializer for 'SAP.Middleware.Connector.RfcDestinationManagers' threw an exception."

     

    I am getting this error when i am developing Web application or website and calling the rfc. I tried every option given here but no outcomes.

     

    Pls help.

Actions