Reputation: 119
I'm using .Net core 2.2 and it's dependency injection. I also inject dependencies from third party libraries. I want to deep clone the object where dependencies are injected. Binary Serialization is not an option as classes from other libraries are not marked as Serializable
. Json serialization and Reflection cloning is not working as many classes do not have default constructors.
I looked at this, this and this but not helping
How should I deep clone objects?
Upvotes: 1
Views: 733
Reputation: 1201
Not sure if this is related to exactly what you're issue may be, but I had same issue and it was due to how I was bringing in the DbContexts in the startup.cs file. I had to remove the LazyLoading for the connection that I was using trying to make the DeepClone. Once I did that, it went back to working as expected.
FROM:
services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DbMaster"), opt => opt.UseRowNumberForPaging()) .EnableSensitiveDataLogging().UseLazyLoadingProxies());
TO:
services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DbMaster"), opt => opt.UseRowNumberForPaging()).EnableSensitiveDataLogging());
Hope that can help.
Upvotes: 1