Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-577

MongoDB.BSON.dll does not Serialize System.Diagnostics.EventlogEntry

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.6
    • Component/s: None
    • Environment:
      .NET 4.0 Visual Studio 2010

      I'm trying to insert an EventLogEntry into a MongoDB collection. I get the following exception:

      MongoDB.Bson.BsonSerializationException was unhandled
      Message=No serializer found for type System.ComponentModel.ISite.
      Source=MongoDB.Bson
      StackTrace:
      at MongoDB.Bson.Serialization.BsonSerializer.LookupSerializer(Type type) in C:\work\rstam\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 594
      at MongoDB.Bson.Serialization.BsonMemberMap.GetSerializer(Type actualType) in C:\work\rstam\mongo-csharp-driver\Bson\Serialization\BsonMemberMap.cs:line 309
      at MongoDB.Bson.Serialization.BsonClassMapSerializer.SerializeMember(BsonWriter bsonWriter, Object obj, BsonMemberMap memberMap) in C:\work\rstam\mongo-csharp-driver\Bson\Serialization\BsonClassMapSerializer.cs:line 546
      at MongoDB.Bson.Serialization.BsonClassMapSerializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, IBsonSerializationOptions options) in C:\work\rstam\mongo-csharp-driver\Bson\Serialization\BsonClassMapSerializer.cs:line 396
      at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, IBsonSerializationOptions options) in C:\work\rstam\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 819
      at MongoDB.Driver.Internal.MongoInsertMessage.AddDocument(Type nominalType, Object document) in C:\work\rstam\mongo-csharp-driver\Driver\Internal\MongoInsertMessage.cs:line 58
      at MongoDB.Driver.MongoCollection.InsertBatch(Type nominalType, IEnumerable documents, MongoInsertOptions options) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 1155
      at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document, MongoInsertOptions options) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 999
      at MongoDB.Driver.MongoCollection.Insert(Type nominalType, Object document) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 983
      at MongoDB.Driver.MongoCollection.Insert[TNominalType](TNominalType document) in C:\work\rstam\mongo-csharp-driver\Driver\Core\MongoCollection.cs:line 947
      at ConsoleApplication2.Program.Main() in c:\Users\zippy\Documents\Visual Studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\Program.cs:line 23
      at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
      at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
      at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
      at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

      I realize this is trivial to work around by creating a PODO with all the event log properties. It would be nice if EventLog serialization would "just work" though.

      Test code:

      using System.Diagnostics;
      using MongoDB.Driver;

      namespace ConsoleApplication2
      {
      class Program
      {
      private static MongoServer server = MongoServer.Create("mongodb://localhost/?safe=true");
      private static MongoDatabase db = server["EventLogs"];
      static void Main()
      {
      foreach(var log in EventLog.GetEventLogs())
      {
      var logName = string.Format("EventLogs.

      {0}

      .

      {1}

      ", log.MachineName, log.LogDisplayName);
      var collection = db[logName];

      foreach (var entry in log.Entries)

      { // Collection gets thrown here: collection.Insert(entry); }

      }
      }
      }
      }

            Assignee:
            Unassigned Unassigned
            Reporter:
            zippy1981 Justin Dearing
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: