10

I am facing a peculiar problem related to a hosted WCF service (.NET Framework 4, IIS 7, Windows 2008 Standard SP2).

After I deployed the service it works fine for some time and it dies on its own by throwing a file not found exception. The exception details are given below.

The application is hosted in IIS7, with a specific app pool pointing to .NET Framework 4 version. I have used FusionLog to find more on the missing assembly no luck. However if I delete all assemblies from the hosted server and copy it again from the build folder it starts working again with absolutely no issues. I am unable to explain this behaviour and searched/ tried a lot to find an answer. To give more information the service is a local assembly and I use Enterprise Library for Exception handling and Logging. The WCF Service us using httpBinding. The assemblies are debug build. Please help.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    ------    
  <!-- Begin .......Exception Handling Configuration-->
  <!-- End .........Exception Handling configuration-->

  <!-- Start .............Logging Configuration-->
  <!--End............ Logging Configuration-->

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
        <identity impersonate="true" />
  </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <defaultDocument>
            <files>
                <add value="Service.svc" />
            </files>
        </defaultDocument>
    </system.webServer>

    <!-- Start WCF ................Settings-->
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" />
      <endToEndTracing propagateActivity="true" activityTracing="true" messageFlowTracing="true" />
    </diagnostics>
    <!-- Begin..Included for Switching off Security-->
    <bindings>
      <basicHttpBinding>
        <binding name="httpBindingConfig" closeTimeout="24.01:00:00" openTimeout="24.01:00:00" receiveTimeout="24.10:00:00" sendTimeout="24.01:00:00" />
      </basicHttpBinding>
    </bindings>
    <!-- End ..Included for Switching off Security-->
    <services>
      <service name="Service">
        <endpoint binding="mexTcpBinding" bindingConfiguration="" name="EndPointMex" contract="ICommunicatorService" />
        <endpoint address="http://<>/Service.svc" binding="basicHttpBinding" bindingConfiguration="" name="EndPointHttp" contract="Reflections.IService" />
        <host>
          <timeouts closeTimeout="24.00:10:00" openTimeout="24.01:00:00" />
        </host>
      </service>
    </services>
    <behaviors>
    <serviceBehaviors>
      <behavior>
        <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
        <serviceMetadata httpGetEnabled="true" />
        <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <!-- End WCF ................Settings-->  
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
 </configuration>

Event Log ----------------------

 Log Name:      Application
    Source:        System.ServiceModel 4.0.0.0
    Date:          7/5/2011 10:39:47 AM
    Event ID:      3
    Task Category: WebHost
    Level:         Error
    Keywords:      Classic
    User:          NETWORK SERVICE
    Computer:      <Masked for Security Reasons>
    Description:
    WebHost failed to process a request.
     Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/12036987
     Exception: System.ServiceModel.ServiceActivationException: The service '/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.
       at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
       at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
       at System.Reflection.Assembly.Load(String assemblyString)
       at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       --- End of inner exception stack trace ---
       at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)
       at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath)
     Process Name: w3wp
     Process ID: 3480

Error displayed in ASP.NET Page-----------------

Server Error in '/' Application.
--------------------------------------------------------------------------------

Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' could not be loaded.


Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
 (Fully-specified)
LOG: Appbase = file://path/
LOG: Initial PrivatePath = \\path\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: \\path\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
LOG: The same bind was seen before, and was failed with hr = 0x80070002.



Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +39
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +132
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +144
   System.Reflection.Assembly.Load(String assemblyString) +28
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +210
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1440
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +615

[ServiceActivationException: The service '/Service.svc' cannot be activated due to an exception during compilation.  The exception message is: Could not load file or assembly 'Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e' or one of its dependencies. The system cannot find the file specified..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +687598
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
   System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +301390
   System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +8898292
-------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

Error in fusion Log

*** Assembly Binder Log Entry  (7/22/2011 @ 10:34:51 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  c:\windows\system32\inetsrv\w3wp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = NT AUTHORITY\NETWORK SERVICE
LOG: DisplayName = Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e
 (Fully-specified)
LOG: Appbase = file://path/
LOG: Initial PrivatePath = \\path\bin
LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b44c783a
LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\b44c783a
LOG: AppName = 34485861
Calling assembly : (Unknown).
===
LOG: Start binding of native image Reflections.Service, Version=1.0.0.0, Culture=en-US, PublicKeyToken=fb2997440781f12e.
WRN: No matching native image found.

There is a similar issue dicussed here but not able to find an anwer Changing the web.config takes the WCF service down?

Community
  • 1
  • 1
Anil S
  • 133
  • 1
  • 9
  • Its looking for a file called Reflections.Service is this the name of the assembly that houses your service? – Richard Blewett Jul 22 '11 at 07:41
  • @Anil - any additional details you can provide on the hadrware environment? Is there any hardware clustering happening here? Also, not that you should have to, but have you considered creating your service as a WCF library and hosting it in IIS manually? This would allow you to throw your service library in the GAC - can't imagine it'd get deleted from there! – Brian Jul 27 '11 at 17:04

1 Answers1

5

Is it possible the file not found is a red herring and you are just experiencing an inactivity timeout? I remember when I wrote my first WCF service I didn't realize the timeout settings defaulted to something fairly short like a couple of minutes. I think you can set them to be very long (like 24 days).

In my app config in the <configuration> section immediately after my <system.web> section I have:

    <system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="tcp_unsecured" receiveTimeout="infinite" sendTimeout="00:00:30">
                <security mode="None">
                </security>
            </binding>
        </netTcpBinding>
    </bindings>

This is followed by my service and behaviors sections. Here's a png of the dialog when I right click and select Edit WCF Configuration on my app.config. I typed "infinite in the app.config xml file but the dialog turns that into the relevant large value. enter image description here

Update: In my mediator class here is the constructor that sets up a NetTcpBinding. I'm including this because it appears I needed to set the timeouts in code.

    public DspServiceMediator( String serviceAddress)
    {
        EndpointAddress end_point = new EndpointAddress(serviceAddress);
        NetTcpBinding new_tcp = new NetTcpBinding(SecurityMode.None)
                                {ReceiveTimeout = TimeSpan.MaxValue,
                                 SendTimeout = new TimeSpan(0, 0, 30)
                                };

        _dspClient = new DspServiceClient(new_tcp, end_point);
    }
Tod
  • 8,192
  • 5
  • 52
  • 93
  • Tod - Thank you for your time, i really appreciate your help. Are you referering to – Anil S Jul 05 '11 at 06:46
  • First let me say I'm no expert and I've only self-hosted and windows service hosted. I'm going to post the section in my app.config I changed, but eventually my service ended up getting pinged by the app via a timer for other reasons so that always kept it from timing out. I'm not sure I ever nailed down the timeout settings. But you may be able to do a better search here on SO now that you know that they exist. – Tod Jul 05 '11 at 18:06
  • Tom - I am still having this issue, the suggested settings did not help. My live service dies down after 15 mts. – Anil S Jul 08 '11 at 10:06
  • The only other thing I can suggest is to try and confirm it is a timeout problem. You can fire up a timer and have it send a request to your service once a minute. If it still dies then it's not a timeout error. – Tod Jul 08 '11 at 22:10
  • I went back and took a look at my instantiation of the WCF Service. I had created a mediator class for the service but the constructor was creating a NetTcpBinding and setting the timeout there. I'll add that code to the end of my reply above (so that it formats). – Tod Jul 09 '11 at 06:43
  • Tod - Thank you very much for your reply - yes its a timeout problem, i tried a little different this time - i changed the timeout settings for the App Pool. Advanced Settings->Idle Time out and Regular Time intervel properties to max values. Now the service is alive and holding. However the only one thing that i dont understand is why should i replace my binaries after a time out, technically an IIS or App Pool restart should get me going - any way the problem is solved for the time being - Thank you very much. – Anil S Jul 11 '11 at 05:46
  • To give you an update its just holds for a day and it dies off - as of now i have created an exe to ping and keep this service alive. I am just wondering rest of the WCF world does not have this issue. – Anil S Jul 20 '11 at 11:43
  • I don't know, maybe most uses don't have a service that runs for long without some sort of interaction. I'll put a bounty on this question for you (you can pay back some of the points that will cost me by upvoting my answer and any comments that were helpful). – Tod Jul 20 '11 at 18:28
  • 1
    I have edited my original question to include web.config file. for upvoting i dont have sufficient points. Appologies. – Anil S Jul 21 '11 at 05:21
  • OH sorry, I didn't realize you needed any reputation to upvote. You did get rep for people upvoting your question. I've been watching some pluralsight videos on WCF trying to find a better answer but so far I haven't even seen a mention about timing out. – Tod Jul 21 '11 at 17:56
  • This ping service is a failure - this is still happening, included more log files. – Anil S Jul 22 '11 at 05:32
  • I guess its not a WCF issue, i have written a simple helloworld service to see hosting issues of server - its holding with out any additional settings changes like timeout etc. I am investigating the use of enterprise library and getting all these assemblies to GAC. I will update you with the result. Thank you so much for your guidance. – Anil S Jul 25 '11 at 05:34