1

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?

Milan
  • 119
  • 2
  • 12

1 Answers1

1

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.

Briana Finney
  • 1,171
  • 5
  • 12
  • 22
  • Thanks! Good to know this but I ended up using some combination of binary serialization and at places AutoMapper – Milan Dec 30 '19 at 23:22