force-net / DeepCloner

Fast object cloner for .NET
MIT License
518 stars 67 forks source link

Exception: An instance of the __ComObject type cannot be created unless the type has been obtained using GetTypeFromProgID or GetTypeFromCLSID. #24

Open sekulicb opened 3 years ago

sekulicb commented 3 years ago

Hi. I got this message by cloning standard DTO object, that inherits from INotifyPropertyChanged interface via Fody. I'm not sure could that be a problem. Thanks

sekulicb commented 3 years ago

Just to add, I'm not coping an object, but the collection of it (cache that we use in the app)

akaBilih commented 1 year ago

Got the same error. Were you able to fix it?

sekulicb commented 1 year ago

Sorry, I have finalized that project at the end of 2021. I think that at some point I changed the library to FastDeepCloner or maybe you have to for each in the object that you are trying to clone, and check something like property.CanRead() or something similar to be able to actually clone the property of the object itself. Hope that helps. Good luck.

force-net commented 1 year ago

This project copies fields (not properties) by design. At start, main idea of project was in fast cloning simple DTO objects. But I try to add support to clone everything. Unfortunately, there are a lot of issues with native resources in .NET and complex objects, when they have some inner field, that references all world. In most complex cases it is hard to correctly clone objects without knowledge about structure of specific library and how it handles objects. I have some ideas, how it can be realized, but I do not have time to do this (I really want to find spare time for this, but currently it is impossible for me). So, I can give advices on github and think about how to implement things in my head :)

Dunge commented 2 days ago

Got the same issue and preventing me to use this lib completely.

All of my model classes that I would possibly want to clone implement propertychanged. Somehow it doesn't crash if I do it in a console app, but get the ComObject error when doing in on a WPF project where the property is bound to the interface. I don't have any COM objects in my classes.

Seems like it clones the event field and all subscribers comes with it.