Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception: No coercion operator is defined between types 'System.Void*' and 'System.Object'. #7

Open
heischo opened this issue Feb 24, 2021 · 2 comments

Comments

@heischo
Copy link

heischo commented Feb 24, 2021

Hi.

I get this exception when I try to clone the object 'NLog.LogManager.Configuration' of type NLog.Config.LoggingConfiguration.
I use the nuget version 2.2.2 in a .NET Core 3.1 project (Console App).

Stack Trace:

   at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
   at System.Linq.Expressions.Expression.Convert(Expression expression, Type type, MethodInfo method)
   at System.Linq.Expressions.Expression.Convert(Expression expression, Type type)
   at ObjectCloner.Internal.DeepCloneExpressionBuilder.CreateRecursiveCallExpression(Expression objectToCopy)
   at ObjectCloner.Internal.DeepCloneExpressionBuilder.<CreateFieldCopyExpressions>d__19.MoveNext()
   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
   at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
   at ObjectCloner.Internal.DeepCloneExpressionBuilder.Build()
   at ObjectCloner.Internal.DeepCloneInternal.<>c__DisplayClass1_0.<GetDeepCloner>b__0(Type t)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at ObjectCloner.Internal.DeepCloneInternal.GetDeepCloner(Type type)
   at ObjectCloner.ObjectCloner.DeepClone[T](T original)
@marcelltoth
Copy link
Owner

Hello,

Thanks for reporting the error. Do you happen to have a repo that contains a repro steps? It's wild guessing without one

@heischo
Copy link
Author

heischo commented Mar 3, 2021

@marcelltoth Hi, no, I don't have a public repo in this case. But I thought it will not be 'wild guessing', because I mentioned clearly which object I try to clone.
Simply use the following code, after installing the nuget package for NLog:

var config = new NLog.Config.LoggingConfiguration();

// Targets where to log to: File and Console
var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "file.txt" };
var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
            
// Rules for mapping loggers to targets            
config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);
            
// Apply config           
NLog.LogManager.Configuration = config;

(see https://github.com/NLog/NLog/wiki/Tutorial)

Then, you can try to clone NLog.LogManager.Configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants