Serializing a StructureMapBuildException doesn't work anymore
See original GitHub issueDue 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:
- Created 5 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My guess is StructureMapBuildException isn’t marked as
[Serializable]
. Exceptions implementISerializable
so before they were serialized using different rules. Now they only do that if they implementISerializable
and are marked as[Serializable]
.Do we have any new information on this issue?