On various development machines there's no issue, but when we deploy a
SolrNet application on our production server, we're ending up with a
"Response is not available in this context" exception when enabling
the ISolrOperations<T>.BuildSpellCheckDictionary(); in
Application_Start. Removing that spell check build call resolves the
issue (but obviously no spell checker built).
I know that for i.e. HttpContext is not available in integrated
pipeline applications in Application_Start, but I've not run into this
issue before and haven't found anyone else with a similar one - hoping
somebody out there will give a shout-out as to what the issue is.
It's an
ASP.NET MVC 3 application running under
ASP.NET 4 on Windows
2008 x64. Not running under Medium Trust. Oh, and SolrNet.0.3.1.0.
Solr instance running on Ubuntu Natty x64.
...a little bit later:
I dug into the source, and it could be simply because in
https://github.com/mausch/SolrNet/blob/master/SolrNet/Impl/SolrConnection.cs
try {
using (var postStream = request.GetRequestStream()) {
CopyTo(content, postStream);
}
return GetResponse(request).Data;
} catch (WebException e) {
var msg = e.Message;
if (e.Response != null) {
using (var s = e.Response.GetResponseStream())
using (var sr = new StreamReader(s))
msg = sr.ReadToEnd();
}
throw new SolrConnectionException(msg, e);
}
There must be an error occurring when attempting to get the response,
but e.Response is not available in Application_Start (and thus
throwing up the rabbit trail HttpException instead of the underlying
issue).
Therefore, I verified by temporarily putting BuildSpellChecker in
Begin_Request (where HttpContext is available) and everything is fine.
I'm thinking then that there's a bug in SolrConnection as e.Response
is not available in integrated pipeline if there's a WebEception that
occurs, but I'll have to figure out what my configuration's issue is
somehow as it's only on our production server and the rethrown
SolrConnectionException is either not occurring with the temporary
switch to Begin_Request or is not being logged anywhere/bubbling all
the way up.
Here's the stack trace:
[HttpException (0x80004005): Response is not available in this
context.]
System.Web.Util.HttpEncoder.get_Current() +11324418
System.Web.HttpUtility.UrlEncode(String str, Encoding e) +132
SolrNet.Impl.SolrConnection.<Get>b__0(KeyValuePair`2 input) in c:
\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:121
SolrNet.Utils.<Select>d__1a`2.MoveNext() in c:\prg\SolrNet\svn
\SolrNet\Utils\Func.cs:132
SolrNet.Utils.Func.Reduce(IEnumerable`1 source, TResult startValue,
Accumulator`2 accumulator) in c:\prg\SolrNet\svn\SolrNet\Utils\Func.cs:
37
SolrNet.Impl.SolrConnection.Get(String relativeUrl, IEnumerable`1
parameters) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:120
SolrNet.Impl.SolrQueryExecuter`1.Execute(ISolrQuery q, QueryOptions
options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrQueryExecuter.cs:308
SolrNet.Impl.SolrBasicServer`1.Query(ISolrQuery query, QueryOptions
options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:83
SolrNet.Impl.SolrServer`1.BuildSpellCheckDictionary() in c:\prg
\SolrNet\svn\SolrNet\Impl\SolrServer.cs:116
abc.xyz.Core.Search.SolrSearchWarmup.Warm() in D:\Projects\Client
Projects\xyz\pqr\trunk\Web\abc.xyz.Core\Search\SolrSearchWarmup.cs:20
abc.xyz.Web.MvcApplication.Application_Start() in D:\Projects
\Client Projects\xyz\pqr\trunk\Web\abc.xyz.Web\Global.asax.cs:49
[HttpException (0x80004005): Response is not available in this
context.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext
context, HttpApplication app) +3988565
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr
appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state,
MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr
appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr
appContext) +375
[HttpException (0x80004005): Response is not available in this
context.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context)
+11529072
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +4784373