eBay .NET SDK is causing my Cache and Session to be restarted

155 Views Asked by At

I am having all kinds of problems with the eBay .NET SDK (http://go.developer.ebay.com/developers/ebay/documentation-tools/sdks/dotnet)

Posted this question the other day:

HttpRuntime.Cache doesn't appear to be working

Now after a lot more investigation, it would seem that in fact calling the eBay API is clearing my .NET Session and Cache data, restarting the application in fact.

WHY?!!

The function which seems to be at fault is my method for grabbing eBay categories. The question above first came about because I was finding I was unable to cache the incredibly slow response I get from eBay... however, it seems I can cache it, but something in the function is causing the application to restart.

Here's how I get categories:

Shared Function DisplayCategories(Optional ParentId As Integer = 0, Optional Level As Integer = 1) As CategoryTypeCollection

    Dim Categories As New CategoryTypeCollection

    Dim apiContext As ApiContext = Credentials.GetApiContext()
    Dim apicall As New GetCategoriesCall(apiContext) With {
        .EnableCompression = True,
        .Site = SiteCodeType.UK,
        .LevelLimit = Level
    }
    If ParentId <> 0 Then _
        apicall.CategoryParent = New StringCollection({"" & ParentId & ""})

    apicall.DetailLevelList.Add(DetailLevelCodeType.ReturnAll)

    'SiteCodeType.UK, New StringCollection({"1"}), 10, False
    Categories = apicall.GetCategories()

    Return Categories

End Function

All caching code removed for simplicity, but I can assure you, running this function clears my cache and any Session data.

Any idea why?!!

1

There are 1 best solutions below

0
On

I think I have the solution to this now... (After two days and the answer is fairly simple too)

The reason was the eBay SDK was storing its api log file in the bin folder which, when edited, caused the application to restart. I added these lines of code to application_end in global.asax

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application ends

    Dim runtime As HttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.[Static] Or Reflection.BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)
    Dim shutDownMessage As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownMessage", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
    Dim shutDownStack As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownStack", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)


End Sub

I then inspected the shutDownMessage and it came back with:

"Change Notification for critical directories. bin dir change or directory rename HostingEnvironment initiated shutdown HostingEnvironment caused shutdown Change Notification for critical directories. bin dir change or directory rename"

I thin checked the bin folder and low and behold the eBayAPiLog.txt file was written there.

I have now changed the code that sets up the eBay Log file to store it in the application root instead.

            'set Api logging
        ApiContext.ApiLogManager = New ApiLogManager
        Dim fileLogger As FileLogger = New FileLogger(String.Concat(AppConfig.SiteRootPath, "eBayAPI_log.txt"), True, True, True)
        ApiContext.ApiLogManager.ApiLoggerList.Add(fileLogger)

With this change the application is no longer recycling and session and cache persist!