www.webdeveloper.com
Results 1 to 9 of 9

Thread: Exception has been thrown by the target of an invocation

  1. #1
    Join Date
    Mar 2010
    Posts
    11

    Exclamation Exception has been thrown by the target of an invocation

    I am writing a ASP.NET (C#) web application. I am using a custom MySQL session provider (session provider class)

    It works great on my production server, but I'm trying to get it to work on my machine so that I can continue developing it, I have run into a few problems while trying to do this, but I have fixed them all except this one.

    When I run the site on my computer through localhost I receive the following error: "Exception has been thrown by the target of an invocation." (Error can be seen in context in the attached image).

    Below are the event contents:

    Code:
    Log Name:      Application
    Source:        ASP.NET 4.0.30319.0
    Date:          1/16/2011 6:30:02 PM
    Event ID:      1310
    Task Category: Web Event
    Level:         Warning
    Keywords:      Classic
    User:          N/A
    Computer:      Christopher-PC
    Description:
    Event code: 3008 
    Event message: A configuration error has occurred. 
    Event time: 1/16/2011 6:30:02 PM 
    Event time (UTC): 1/16/2011 5:30:02 AM 
    Event ID: 5b7a15443ee64ba4856923b0fb1bc751 
    Event sequence: 8 
    Event occurrence: 7 
    Event detail code: 0 
     
    Application information: 
        Application domain: /LM/W3SVC/2/ROOT-1-129396289941470000 
        Trust level: Full 
        Application Virtual Path: / 
        Application Path: C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\ 
        Machine name: CHRISTOPHER-PC 
     
    Process information: 
        Process ID: 5476 
        Process name: w3wp.exe 
        Account name: IIS APPPOOL\Pixelate CMS 
     
    Exception information: 
        Exception type: ConfigurationErrorsException 
        Exception message: Exception has been thrown by the target of an invocation. (C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\web.config line 24)
       at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
       at System.Web.SessionState.SessionStateModule.SecureInstantiateProvider(ProviderSettings settings)
       at System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication app, SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.Init(HttpApplication app)
       at System.Web.HttpApplication.InitModulesCommon()
       at System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers)
       at System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context)
       at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
       at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
    
    Exception has been thrown by the target of an invocation.
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Web.HttpRuntime.CreatePublicInstance(Type type)
       at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
    
    Response is not available in this context.
       at System.Web.HttpContext.get_Response()
       at Pixelate.MySqlSessionStateStore..ctor() in C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\classes\MySqlSessionStateStore.cs:line 75
    
     
     
    Request information: 
        Request URL: http://pixelatecms.com.localhost/pokeintest.aspx 
        Request path: /pokeintest.aspx 
        User host address: 127.0.0.1 
        User:  
        Is authenticated: False 
        Authentication Type:  
        Thread account name: Christopher-PC\Christopher 
     
    Thread information: 
        Thread ID: 15 
        Thread account name: Christopher-PC\Christopher 
        Is impersonating: False 
        Stack trace:    at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
       at System.Web.SessionState.SessionStateModule.SecureInstantiateProvider(ProviderSettings settings)
       at System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication app, SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.Init(HttpApplication app)
       at System.Web.HttpApplication.InitModulesCommon()
       at System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers)
       at System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context)
       at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
       at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
     
     
    Custom event details: 
    
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="ASP.NET 4.0.30319.0" />
        <EventID Qualifiers="32768">1310</EventID>
        <Level>3</Level>
        <Task>3</Task>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2011-01-16T05:30:02.000000000Z" />
        <EventRecordID>9698</EventRecordID>
        <Channel>Application</Channel>
        <Computer>Christopher-PC</Computer>
        <Security />
      </System>
      <EventData>
        <Data>3008</Data>
        <Data>A configuration error has occurred.</Data>
        <Data>1/16/2011 6:30:02 PM</Data>
        <Data>1/16/2011 5:30:02 AM</Data>
        <Data>5b7a15443ee64ba4856923b0fb1bc751</Data>
        <Data>8</Data>
        <Data>7</Data>
        <Data>0</Data>
        <Data>/LM/W3SVC/2/ROOT-1-129396289941470000</Data>
        <Data>Full</Data>
        <Data>/</Data>
        <Data>C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\</Data>
        <Data>CHRISTOPHER-PC</Data>
        <Data>
        </Data>
        <Data>5476</Data>
        <Data>w3wp.exe</Data>
        <Data>IIS APPPOOL\Pixelate CMS</Data>
        <Data>ConfigurationErrorsException</Data>
        <Data>Exception has been thrown by the target of an invocation. (C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\web.config line 24)
       at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
       at System.Web.SessionState.SessionStateModule.SecureInstantiateProvider(ProviderSettings settings)
       at System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication app, SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.Init(HttpApplication app)
       at System.Web.HttpApplication.InitModulesCommon()
       at System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers)
       at System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context)
       at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
       at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
    
    Exception has been thrown by the target of an invocation.
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Web.HttpRuntime.CreatePublicInstance(Type type)
       at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
    
    Response is not available in this context.
       at System.Web.HttpContext.get_Response()
       at Pixelate.MySqlSessionStateStore..ctor() in C:\Users\Christopher\Documents\Twisted Pixel\Twisted Pixel\Pixelate\classes\MySqlSessionStateStore.cs:line 75
    
    </Data>
        <Data>http://pixelatecms.com.localhost/pokeintest.aspx</Data>
        <Data>/pokeintest.aspx</Data>
        <Data>127.0.0.1</Data>
        <Data>
        </Data>
        <Data>False</Data>
        <Data>
        </Data>
        <Data>Christopher-PC\Christopher</Data>
        <Data>15</Data>
        <Data>Christopher-PC\Christopher</Data>
        <Data>False</Data>
        <Data>   at System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)
       at System.Web.SessionState.SessionStateModule.SecureInstantiateProvider(ProviderSettings settings)
       at System.Web.SessionState.SessionStateModule.InitCustomStore(SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.InitModuleFromConfig(HttpApplication app, SessionStateSection config)
       at System.Web.SessionState.SessionStateModule.Init(HttpApplication app)
       at System.Web.HttpApplication.InitModulesCommon()
       at System.Web.HttpApplication.InitInternal(HttpContext context, HttpApplicationState state, MethodInfo[] handlers)
       at System.Web.HttpApplicationFactory.GetNormalApplicationInstance(HttpContext context)
       at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
       at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
    </Data>
      </EventData>
    </Event>
    Thanks for any help anyone can provide.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2011
    Posts
    6
    Hi Neaox,
    We are currently looking for a full time permanent Software Developer in Illinois. Do you know of anyone that is looking to change companies?
    Thanks!

  3. #3
    Join Date
    Mar 2010
    Posts
    11

    Exclamation Found a Fix (Sort-of)

    I found a work-around - The Application Pool mode on my production server was set to "classic" and the Application Pool mode on my machine (by default) was set to "Integrated", by changing this to "Classic" the error no longer occurs. However, am I to understand that "Integrated" is the new, and preferred Application Pool mode? If so how can I get this class to work under such a mode? Is it just differing syntax?

    Thanks for any help.

  4. #4
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    sounds like your using different versions of IIS on both machines.


    Integrated application pool mode

    When an application pool is in Integrated mode, you can take advantage of the integrated request-processing architecture of IIS and ASP.NET. When a worker process in an application pool receives a request, the request passes through an ordered list of events. Each event calls the necessary native and managed modules to process portions of the request and to generate the response. There are several benefits to running application pools in Integrated mode. First the request-processing models of IIS and ASP.NET are integrated into a unified process model. This model eliminates steps that were previously duplicated in IIS and ASP.NET, such as authentication. Additionally, Integrated mode enables the availability of managed features to all content types.

    Classic application pool mode

    When an application pool is in Classic mode, IIS 7.0 handles requests as in IIS 6.0 worker process isolation mode. ASP.NET requests first go through native processing steps in IIS and are then routed to Aspnet_isapi.dll for processing of managed code in the managed runtime. Finally, the request is routed back through IIS to send the response. This separation of the IIS and ASP.NET request-processing models results in duplication of some processing steps, such as authentication and authorization. Additionally, managed code features, such as forms authentication, are only available to ASP.NET applications or applications for which you have script mapped all requests to be handled by aspnet_isapi.dll. Be sure to test your existing applications for compatibility in Integrated mode before upgrading a production environment to IIS 7.0 and assigning applications to application pools in Integrated mode. You should only add an application to an application pool in Classic mode if the application fails to work in Integrated mode. For example, your application might rely on an authentication token passed from IIS to the managed runtime, and, due to the new architecture in IIS 7.0, the process breaks your application.
    quote from: http://stackoverflow.com/questions/7...pppool-in-iis7

    regards


    Ribs
    ----------------------------------

  5. #5
    Join Date
    Mar 2010
    Posts
    11

    Thumbs up

    Quote Originally Posted by Ribeyed View Post
    sounds like your using different versions of IIS on both machines.



    quote from: http://stackoverflow.com/questions/7...pppool-in-iis7

    regards


    Ribs
    Thanks for taking the time to reply.

    I believe that both servers were/are using IIS7, as I said I have a feeling the Application Pool Mode on the production server was set to "Classic" - Now I can't confirm this as the production server is a shared environment, and I don't have access to the Application Pool settings for that server, that being said the reason I believe this is so is because when I switch to "Classic" AP mode the error no longer occurs, and I see how this would lead you to your conclusion and it very well may be valid, but either way it appears that either the syntax used in the web.config to define the custom Session State provider is incompatible with "Integrated" AP mode or IIS6 as you mentioned, or the MySQLSessionState provider class (the syntax used) is not compatible with "Integrated" AP Mode or IIS6.

    Can you shed any light on to why this may be?

    On another note I have another minor problem with the same class, it's a non-issue but worth figuring out why it occurs:

    If you look at the bottom of the event log for the Exception you'll notice the error "Response is not available in this context." - I understand that this occurs when you try to access the Response object outside of the page context. However in this case the Response object is created thus:

    HttpResponse Response = HttpContext.Current.Response;

    This should work, however it obviously is not in this case as the error occurs, I can't fathom why this would be the case. This is not a major issue as the Response object is just used to output simple errors through a try/catch system, I digress...

    The point is I wouldn't think that this would have any correlation with the main Exception, but due to the fact that it is included in the Event log I didn't want to disregard it.

    Apologies for the drawn out reply but I wanted to be as informative as I could be.

    Thanks for any help that can be given.

    Chris

  6. #6
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi Chris,

    I can see you have a couple of issues but if its ok I would like to just focus on the first one then if I have time I will try help with the next one. Maybe you can split up your topics, maybe someone else can help with your second issue.

    Logic dictates that there is a difference between your machine and the production machine, obviously . So I would be asking myself what is different. Your right to query why it works with classic applicationpool and not Intergrated.

    If you remove the sessionprovider stuff does the website run? You didn't show code for your actual connection string, maybe the problem is the connection string.

    I've never used mySQL however google has said that you needed to download the MySQL .NET connector, maybe version 5.0.7?? Have you got the same MySQL .Net connector on both machines?

    here is a small artical just to double check your connection string and provider code:

    http://www.codeproject.com/KB/sessio..._in_MySql.aspx

    Let me know how it goes.

    regards


    Ribs
    ----------------------------------

  7. #7
    Join Date
    Mar 2010
    Posts
    11
    Quote Originally Posted by Ribeyed View Post
    Hi Chris,

    I can see you have a couple of issues but if its ok I would like to just focus on the first one then if I have time I will try help with the next one. Maybe you can split up your topics, maybe someone else can help with your second issue.

    Logic dictates that there is a difference between your machine and the production machine, obviously . So I would be asking myself what is different. Your right to query why it works with classic applicationpool and not Intergrated.

    If you remove the sessionprovider stuff does the website run? You didn't show code for your actual connection string, maybe the problem is the connection string.

    I've never used mySQL however google has said that you needed to download the MySQL .NET connector, maybe version 5.0.7?? Have you got the same MySQL .Net connector on both machines?

    here is a small artical just to double check your connection string and provider code:

    http://www.codeproject.com/KB/sessio..._in_MySql.aspx

    Let me know how it goes.

    regards


    Ribs
    Hi Ribs,

    Thanks again for you help.

    Yes, if I set the SessionState mode to "Off" or "InProc" etc the error does not occur.

    The connection string is valid as I have no problem querying my database, there are a few syntax variations for a connection string, but all should suffice.

    In reference to the MySQL .NET connector, both servers were/are supplied the same .dll files, they are located in the bin folder of the project and are referenced just the same. The first thing I did when I experienced this problem was to upgrade to the latest connector pack - this did not solve the problem .

    All I do is publish the project, both servers/machines had/have access to the exact same files/classes.

    It's a puzzler.

    Thanks ribs for taking the time to help me, your a trooper.

  8. #8
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi Chris,

    I've tired to configure your enviroment so I can see whats going on.

    Windows 7 ult OS
    Visual Studio 2010
    .NET Framework 4
    MySQL 5.5.8
    MySQL Connector net 5.0.9

    Installed MySQL then the connectors. Downloaded your session provider class. Created a blank ASP.NET project in VS targeting .NET framework 4. Added a reference to MySQLData.dll added the MySqlSessionStateStore.cs to my project and rebuild.

    Few errors occured in the class.

    'MySql.Data.MySqlClient.MySqlDbType' does not contain a definition for 'DateTime'
    added this to my web.config
    Code:
     <system.web> 
        <sessionState cookieless="false" regenerateExpiredSessionId="true" 
                   mode="Custom" customProvider="MySqlSessionProvider"> 
          <providers> 
            <add name="MySqlSessionProvider" 
               type="Samples.AspNet.Session.MySqlSessionStateStore" 
               connectionStringName="MySqlSessionServices" 
               writeExceptionsToEventLog="false"/> 
          </providers> 
        </sessionState>
      </system.web>
    Now visual studio didn't like:

    Code:
                 connectionStringName="MySqlSessionServices"
                 writeExceptionsToEventLog="false"
    error:

    The connectionStringName attribue not allowed.

    Doesn't matter which framework I target I still get the same error.

    Questions:

    Are you using Visual Studio and if so which version?
    Which .NET framework you ahve installed?
    Have you complied your code on the machine with that problem?

    regards

    Ribs
    ----------------------------------

  9. #9
    Join Date
    Feb 2011
    Posts
    1
    Hi neaox,


    It looks to me (reading the stack trace) that the problem is not that the syntax of configuring the SessionProvider is different apps running in classic and integrated mode: The problem is that the "Response is not available in this context." exception is being raised when the system is trying to instantiate the session provider. The system is wrapping this inner exception in a configuration exception.

    I bet if you were to comment out MySqlSessionStateStore.cs:line 75 (assuming that were possible) then this issue would go away.

    [I am totally guessing here] The reason why the code worked in Classic mode and is not working in integrated mode is very similar to why you cannot access HttpContext.Current in Global.Application_Start whilst running in integrated mode (see this link).. In classic mode, IIS handles the request before passing it to the ASP via ISAPI - perhaps IIS had already created a response stream by this point and so could pass that to the ISAPI handler? Perhaps, in integrated mode, the session store initialization occurs before a response has been setup (you can tell I am grasping here!).


    But if you think about it, accessing the current http context is a rather odd thing to do in the initialization of the session store - this would imply that the store would initialize differently depending on request that activated the web application. I would check your code and see if you are calling logic in the init of the store that would be more appropriate in the creation/init of an individual session.


    Hope that makes sense.

    If you have figured out the problem of how to get your code working in integrated mode, then please post the answer here - I have run into several issues running our old web app in integrated mode and you can be sure that sooner or later I will encounter an issue similar to what you are experiencing!

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles