in

NIMTUG

Northern Ireland Microsoft Technologies User Group

Damien McGivern

January 2008 - Posts

  • WCF requires precompiled ASP.Net sites to be updatable

    Today I was testing a deployment ASP.Net site build that I added some WCF services to. All other non deployment builds passed all testing so I was stumped when testing one of the services I got the following error.

     

    Value cannot be null.
    Parameter name: key

    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.ArgumentNullException: Value cannot be null.
    Parameter name: key

    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.

    Stack Trace:

    [ArgumentNullException: Value cannot be null.
    Parameter name: key]
    System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument) +51
    System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +5295964
    System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) +20
    System.ServiceModel.Activation.MetabaseSettingsIis.GetTransportSettings(String virtualPath) +154
    System.ServiceModel.Activation.MetabaseSettingsIis.GetAccessSslFlags(String virtualPath) +9
    System.ServiceModel.Activation.HttpHostedTransportConfiguration.GetBaseAddresses(String virtualPath) +113
    System.ServiceModel.Activation.HostedTransportConfigurationManager.InternalGetBaseAddresses(String virtualPath) +146
    System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +162
    System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +46
    System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +738

    [ServiceActivationException: The service '/demo2/services/memberservice.svc' cannot be activated due to an exception during compilation. The exception message is: Value cannot be null.
    Parameter name: key.]
    System.ServiceModel.AsyncResult.End(IAsyncResult result) +7571873
    System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +4504815
    System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +288
    System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +273
    System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +177


    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
     

     

     

    The only difference with the deployment build is that the website is precompiled and the assemblies merged. Then I checked the even log and noticed that for every request of  memberservice.svc the following two errors occurred.

     

    Event Type:    Error
    Event Source:    System.ServiceModel 3.0.0.0
    Event Category:    WebHost
    Event ID:    3
    Date:        30/01/2008
    Time:        11:30:35
    User:        NT AUTHORITY\NETWORK SERVICE
    Computer:    ELGRECO
    Description:
    WebHost failed to process a request.
     Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/30607723
     Exception: System.ServiceModel.ServiceActivationException: The service '/demo2/services/memberservice.svc' cannot be activated due to an exception during compilation.  The exception message is: Value cannot be null.
    Parameter name: key. ---> System.ArgumentNullException: Value cannot be null.
    Parameter name: key
       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
       at System.ServiceModel.Activation.MetabaseSettingsIis.GetTransportSettings(String virtualPath)
       at System.ServiceModel.Activation.MetabaseSettingsIis.GetAccessSslFlags(String virtualPath)
       at System.ServiceModel.Activation.HttpHostedTransportConfiguration.GetBaseAddresses(String virtualPath)
       at System.ServiceModel.Activation.HostedTransportConfigurationManager.InternalGetBaseAddresses(String virtualPath)
       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: 708

    Followed by:

    Event Type:    Error
    Event Source:    System.ServiceModel 3.0.0.0
    Event Category:    WebHost
    Event ID:    3
    Date:        30/01/2008
    Time:        11:30:35
    User:        NT AUTHORITY\NETWORK SERVICE
    Computer:    ELGRECO
    Description:
    WebHost failed to process a request.
     Sender Information: System.ServiceModel.Activation.HostedHttpRequestAsyncResult/49972132
     Exception: System.ServiceModel.ServiceActivationException: The service '/demo2/services/memberservice.svc' cannot be activated due to an exception during compilation.  The exception message is: Value cannot be null.
    Parameter name: key. ---> System.ArgumentNullException: Value cannot be null.
    Parameter name: key
       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
       at System.ServiceModel.Activation.MetabaseSettingsIis.GetTransportSettings(String virtualPath)
       at System.ServiceModel.Activation.MetabaseSettingsIis.GetAccessSslFlags(String virtualPath)
       at System.ServiceModel.Activation.HttpHostedTransportConfiguration.GetBaseAddresses(String virtualPath)
       at System.ServiceModel.Activation.HostedTransportConfigurationManager.InternalGetBaseAddresses(String virtualPath)
       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.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result)
     Process Name: w3wp
     Process ID: 708

     

     After a bit of searching I found the following post http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1150859&SiteID=1 which states that WCF hosted in a precompiled ASP.Net site requires the site to be updatable. So adding the -u switch to our build scrip which calls aspnet_compiler solved the problem.

     

  • Cryptic error messges in WCF?

    I've recently started working with WCF on a project at work, I've read about it and played about with it but never got into any depth with it before now. So far it's going well except for a few cryptic errors I was getting when running my unit tests for a patictular service. The error in was:

    Error    1    TestCase 'CPD.Services.Test.CourseTest.Test10'
    failed: System.ServiceModel.CommunicationException : An error occurred while receiving the HTTP response to https://lap001.office.aurion.co.uk/cpdengage/Services/CourseService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
      ----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive.
      ----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
      ----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host

    Server stack trace:
       at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at CPD.Services.Test.CourseServiceReference.CourseService.GetCourseHeader()
       at CPD.Services.Test.CourseServiceReference.CourseServiceClient.GetCourseHeader() in c:\users\damien.mcgivern\documents\dev\aurion\cpdengage\src\cpd.services.test\service references\courseservicereference\reference.cs:line 1027
       at CPD.Services.Test.CourseTest.Test10() in C:\Users\damien.mcgivern\Documents\dev\aurion\cpdengage\src\CPD.Services.Test\CourseTest.cs:line 157
    --WebException
       at System.Net.HttpWebRequest.GetResponse()
       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
    --IOException
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
       at System.Net.Security._SslStream.StartFrameHeader(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
       at System.Net.Security._SslStream.StartReading(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
       at System.Net.Security._SslStream.ProcessRead(Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
       at System.Net.TlsStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
       at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
    --SocketException
       at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
       at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)    c:\users\damien.mcgivern\documents\dev\aurion\cpdengage\src\cpd.services.test\service references\courseservicereference\reference.cs    1027

     

    It was the first method that used a generic collection and at first I thought this may be to fault but testing other generic collections proved that I was using them correctly (see http://msdn2.microsoft.com/en-us/library/system.runtime.serialization.collectiondatacontractattribute.aspx)

    But just to make sure I wrote a test method that only returned the type that was being used for the generic collection items, and indeed it still failed with the same error.

    This got me thinking that I must have defined the DataContract or DataMember attributes for the object incorrectly, going through each of them I noticed the following code:

    [DataMember(IsRequired = true, EmitDefaultValue = false, Order = 5)]
    public bool IsEnabled

    The value for IsEnabled was always false in the test data, when I set this to true the error never happened and then changing the attributes IsRequired to false stopped the error altogether. Checking the code I found a few other value types that had IsRequired set to true these hadn't and so far no more errors. So setting a value type DataMember to true will cause thie error if the value is the value types default value, bool = false, int = 0 etc.

    What bugs me is that this seems to be a serialisation issue, in that the object doesn't match the requirements defined in the DataContract, however the error message doesn't seem to indicate this at all.

     

     

    Updated 24 June 2008: also see http://msdn.microsoft.com/en-us/library/aa347792.aspx#Mtps_DropDownFilterText - states that SerializationException is thrown. Although the exception details don't make it down to the client.

     


     

NIMTUG 2004-2007
Powered by Community Server (Non-Commercial Edition), by Telligent Systems