Comments (3)
There are actually cares where it appears NClone gets stuck in an infinite loop. I'll try to create a minimal example to demonstrate the issue. I think both the NRE and infinite looping are related to the same issue of the internal dictionary not being thread-safe. I believe the issues are likely to arise when NClone is concurrently asked to clone the same type on different threads before the internal cache for that type has been fully constructed.
from nclone.
The below program (tested targeting .NET Framework 4.5.2 with NClone version 1.1.1 from Nuget) consistently reproduces both the NRE and the infinite looping. The NRE happens almost every time, the infinite looping less often but still frequently enough to see the issue.
using System;
using System.Linq;
using System.Threading.Tasks;
namespace NCloneBug
{
class Program
{
public class ValueObject
{
private readonly int _blah;
private ValueObject() : this(Int32.MinValue){}
public ValueObject(int blah)
{
_blah = blah;
}
public static readonly ValueObject Empty = new ValueObject();
}
public class Entity
{
private ValueObject _foo1 = NClone.Clone.ObjectGraph(ValueObject.Empty);
public ValueObject Foo1
{
get { return _foo1; }
set {_foo1 = value; }
}
private ValueObject _foo3 = NClone.Clone.ObjectGraph(ValueObject.Empty);
public ValueObject Foo3
{
get { return _foo3; }
set { _foo3 = value; }
}
}
static void Main(string[] args)
{
Parallel.ForEach(Enumerable.Repeat<Func<Entity>>(() => new Entity(), 20), x =>
{
try
{
x();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
});
}
}
}
from nclone.
Thank you for reporting and fixing this one! I'll try to release a new version today.
from nclone.
Related Issues (9)
- NClone returns the same object in cases where the original objects were value equal, but not reference equal HOT 1
- Trying to compile NClone from Github HOT 5
- mijay.Utils is not available HOT 1
- Default ctor is not invoked during replication HOT 5
- CircularReference management HOT 3
- Deep clone of structures HOT 1
- Deep cloning of Dictionarys
- Porting to .NET Core HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nclone.