question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serializing a StructureMapBuildException doesn't work anymore

See original GitHub issue

Due to an mistake in our code where something threw an exception while resolving an instance through StructureMap we discovered that there is a serialization problem in version 11.*. In our AspNetCore Application this results in a StackOverflowException.

When using version 10.* the StructureMapBuildException object serializes as expected and very fast.

You can reproduce it with the following code in a console app.

Program.cs:

using System;
using System.Threading;
using Newtonsoft.Json;
using StructureMap;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            TestMethod();
        }

        private static void TestMethod()
        {
            var container = new Container(
                x =>
                    x.For<ITest>()
                        .Use(y => ThrowException()));

            try
            {
                container.GetInstance<ITest>();
            }
            catch (Exception e)
            {
                string serializedObject = JsonConvert.SerializeObject(e); // Will get stuck here using newtonsoft.json version 11.0.2
                Console.WriteLine(serializedObject); // Reaches this with no problem in version 10
            }
        }

        private static Test ThrowException()
        {
            throw new NotImplementedException();
        }
    }

    interface ITest { }
    class Test : ITest { }
}

ConsoleApp.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="StructureMap" Version="4.6.1" />
  </ItemGroup>

</Project>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesNKcommented, Oct 10, 2018

My guess is StructureMapBuildException isn’t marked as [Serializable]. Exceptions implement ISerializable so before they were serialized using different rules. Now they only do that if they implement ISerializable and are marked as [Serializable].

0reactions
AlexEndriscommented, Oct 10, 2018

Do we have any new information on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Structuremap is struggling with NSwag build, any clue ? #662
Runtime.Serialization.SerializationException: Type 'StructureMap.StructureMapConfigurationException' in Assembly 'StructureMap, Version=4.5.0.0, ...
Read more >
c# - Structure map HttpSessionLifecycle object serialization
The problem was in StructureMap. I've added the [Serializable] attribute to the MainObjectCache class and some others and tested it out.
Read more >
Index (AspectJ Tools (Compiler) 1.9.7 API) - javadoc.io
Indicates an open module in module-info file (added in Java SE 9). ... Module name for package/type lookup that doesn't care about modules....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found