question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Record failure on .NET (ok until 3.0.28)

See original GitHub issue

I updated LanguageExt in a project and now get errors.

Version 3.0.28 works, Version 3.0.31 and 3.1.13 raise errors in my project. I have a unit test showing the problem in my code but I could not reproduce it outside of my project. After copying the test and types into LanguageExt source code (test project) the test is green there (current master == 3.1.13). I’m confused why same test shows different behaviour.

My guess: it is something around 2f1e06.

System.TypeInitializationException: The type initializer for 'LanguageExt.RecordType`1' threw an exception.
   at LanguageExt.Record`1.Equals(RECORDTYPE other)
   at MyProject.Actors.MyStaticClass.MyRecordClass.Equals(MyRecordClass rhs) in MyStaticClass.cs:line 488
   at Xunit.Sdk.AssertEqualityComparer`1.Equals(T x, T y)
   at Xunit.Assert.Equal[T](T expected, T actual, IEqualityComparer`1 comparer)
   at Xunit.Assert.Equal[T](T expected, T actual)
   at MyProject.Actors.MyTests.TestMyRecordClass() in MyTests.cs:line 22
System.InvalidOperationException: CompileToMethod cannot compile constant 'MyProject.Actors.MyStaticClass+MyRecordClass' because it is a non-trivial value, such as a live object. Instead, create an expression tree that can construct this value.
   at System.Linq.Expressions.Compiler.BoundConstants.EmitConstant(LambdaCompiler lc, Object value, Type type)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitConstant(Object value, Type type)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitConstantExpression(Expression expr)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitUnliftedAndAlso(BinaryExpression b)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitAndAlsoBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitTypeBinaryExpression(Expression expr)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitBranchComparison(Boolean branch, BinaryExpression node, Label label)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpressionAndBranch(Boolean branchValue, Expression node, Label label)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitUnliftedAndAlso(BinaryExpression b)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitAndAlsoBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitUnliftedAndAlso(BinaryExpression b)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitAndAlsoBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitUnliftedAndAlso(BinaryExpression b)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitAndAlsoBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitUnliftedOrElse(BinaryExpression b)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitOrElseBinaryExpression(Expression expr, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody(CompilerScope parent, Boolean inlined, CompilationFlags flags)
   at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody()
   at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, MethodBuilder method, DebugInfoGenerator debugInfoGenerator)
   at System.Linq.Expressions.LambdaExpression.CompileToMethodInternal(MethodBuilder method, DebugInfoGenerator debugInfoGenerator)
   at LanguageExt.IL.Compile[F](LambdaExpression lambda, String typeName, String methodName)
   at LanguageExt.IL.Equals[A](Boolean includeBase)
   at LanguageExt.RecordType`1..cctor()
public static class MyStaticClass
{
	internal class MyRecordClass : Record<MyRecordClass>
	{
		public MyRecordClass(MyEvent @event)
		{
			Name = @event.Name;
			BirthDay = @event.BirthDay;
		}

		public MyRecordClass(string name, DateTime birthDay)
		{
			Name = name;
			BirthDay = birthDay;
		}

		public DateTime BirthDay { get; }

		[OptOutOfEq, OptOutOfHashCode, OptOutOfOrd]
		//[Eq(typeof(EqStringOrdinalIgnoreCase))]
		public string Name { get; }

		public override bool Equals(MyRecordClass rhs) =>
			base.Equals(rhs) && EqStringOrdinalIgnoreCase.Inst.Equals(rhs.Name, Name);
	}
}
[Fact]
public static void BirthdayTest()
{
	var key1 = new MyStaticClass.MyRecordClass("john", DateTime.Parse("2018-09-19"));
	var key2 = new MyStaticClass.MyRecordClass("John", DateTime.Parse("2018-09-19"));
	var key3 = new MyStaticClass.MyRecordClass("Jane", DateTime.Parse("2018-09-19"));
	Assert.Equal(key1, key2);
	Assert.NotEqual(key3, key2);
	Assert.Equal(0, key1.CompareTo(key2));
	Assert.Equal(key1.GetHashCode(), key2.GetHashCode());
}

I tested the new attributes / NonStructural – same problem.

Any idea how to reproduce this in LanguageExt / what the difference might be?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
StefanBertelscommented, Jan 4, 2019

@louthy: Happy new year!

I looked into this but I could not find out why exactly this fails / how to fix the optimized code. After reverting the change 2f1e06 (see PR #531) tests are green again.

0reactions
louthycommented, Feb 8, 2019

This has the original lambda.Compile() restored (thanks @StefanBertels ) - and is now deploy in https://github.com/louthy/language-ext/releases/tag/v3.1.15

Read more comments on GitHub >

github_iconTop Results From Across the Web

RMS-Net User Manual
RMS-NET Suite is a modern software package providing an organisation with a tightly integrated management and safety system capable of local ...
Read more >
Release 9.18.4 Internet Systems Consortium
failure messages that occur before logging is established are ... domain hosts includes NS and MX records defined above.
Read more >
Bug listing with status UNCONFIRMED as at 2023/07/13 17 ...
Bug:128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils not sys-apps/net-tools" status:UNCONFIRMED resolution: severity:enhancement ...
Read more >
Unity Connection .NET REST SDK
Although the HTTP response is 200 (OK) the call is a failure so the Success flag is false (as it should be). Normally...
Read more >
MySQL Connector/ODBC Developer Guide
Retrieving results (if any). Processing errors. Committing or rolling back the transaction enclosing the SQL statement. Disconnecting from the MySQL server.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found