Registered Convention Not Applied

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.4
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have created a Convention in my Asp.Net MVC application to map between using a string Id property in my classes and a BsonId in the database. I register this convention at startup via the Application_Start method in my Global.asax:

      ConventionRegistry.Register("Custom Conventions", new ConventionPack

      { new StringObjectIdConvention()}

      , t => t.FullName.StartsWith("MyProjectName."));

      The convention works as expected but when deployed to server it will fail to apply after some amount of time (the error will occur when retrieving data from the database and I will get an "System.FormatException: An error occurred while deserializing the Id property of class "ClassName": Cannot deserialize a 'String' from BsonType 'ObjectId'".). This can sometimes be immediately after deployment or after a seemingly random amount of time. In order to get the convention to work again I have to restart the App Pool.

      Is there anything I am doing wrong that could cause this behavior? Is there any way I can check if the convention is still registered when the error occurs?

      As an aside, I am also using Hangfire with Mongo as it's storage in the same web application (using the official Hangfire Mongo driver). Although my registered convention should not apply to to the Hangfire storage (since I apply the filter when registering) is there any chance that this could somehow be interfering? When Hangfire has been disabled I have not noticed the error.

            Assignee:
            Robert Stam
            Reporter:
            Michael Georghion
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: