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

Blazor WebAssembly : "where" error in release mode #461

Closed
Saeidasadi32 opened this issue Nov 21, 2020 · 19 comments
Closed

Blazor WebAssembly : "where" error in release mode #461

Saeidasadi32 opened this issue Nov 21, 2020 · 19 comments
Labels

Comments

@Saeidasadi32
Copy link

I use where with string parameter and run correctly in debug mode.
but when i use release mode system has generate error

@zspitz
Copy link

zspitz commented Nov 21, 2020

  1. What does your code look like?
  2. What is your predicate? In other words, what string are you passing in to Where?
  3. What exception are you getting? Include the stack trace.
  4. What is the shape of the objects you are querying?
  5. Is it possible you are querying different objects in release mode?

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 21, 2020 via email

@zspitz
Copy link

zspitz commented Nov 21, 2020

  1. What is the compile-time type of Freports? IEnumerable? IEnumerable<Freport>?
  2. What is at the ElementType property of Freports after the query, and before the ToList?
  3. What is the shape of that type? public class ...

And you still haven't answered my previous question:

  1. Is it possible you are querying different objects in release mode?

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 21, 2020 via email

@zspitz
Copy link

zspitz commented Nov 21, 2020

From what I can see, the syntax looks fine, and it should work in both Debug and Release mode.

  1. I don't see the LST property/field in the definition you posted.
  2. Again, is it possible the query is being run against different objects in release mode?
  3. Are we talking about Preports? Or Freports?

Please try to use Markdown formatting for code and lists; it makes things much easier to read.

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 21, 2020 via email

@zspitz
Copy link

zspitz commented Nov 21, 2020

  1. What framework are you targeting?
  2. What version of Dynamic LINQ?
  3. Which version of Visual Studio are you using, if any? Or, if you're using another editor, please specify.

@zspitz
Copy link

zspitz commented Nov 21, 2020

This is the code I am using to try and reproduce your exception; it works in both Debug and Release mode:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;

var formula = "(PE > 0.0) && (PE < 15.0 ) &&  (LST > 300.0)";
var FReports = new List<SReport>();
FReports = FReports.AsQueryable().Where(formula).OrderBy(x => x.PE).ToList();

foreach (var x in FReports) {
    Console.WriteLine(x);
}

public class SReport {
    public double PE { get; set; }
    public double LST { get; set; }
}

Using:

  • Visual Studio 2019 (16.8.1)
  • Targeting .NET 5
  • Dynamic LINQ 1.2.5

I can't think of what else to try.

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 21, 2020 via email

@zspitz
Copy link

zspitz commented Nov 21, 2020

I've never used C# to generate WebAssembly. Can you post a sample project with code that reproduces this issue?

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 22, 2020 via email

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 22, 2020 via email

@zspitz
Copy link

zspitz commented Nov 22, 2020

I replace all '&&' with '&'

That may be a different operation; it's interpreted as a bitwise AND, and may produce different results.

& also produces a logical AND when the two operands are boolean; see below.

@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 22, 2020 via email

@zspitz
Copy link

zspitz commented Nov 22, 2020

OK. I can confirm the following:

  • the && operator between two bools causes an exception when run in Release mode, but not in Debug mode.
  • & works in both Debug and Release; the expression tree is still built correctly as a logical AND between two bools.
  • Neither operand seems to be a bool?.
  • The types of the two operands are equivalent -- expr.Left.Type == expr.Right.Type returns true

The following code also produces the same error only in Release mode, not in Debug mode:

    var prm = System.Linq.Expressions.Expression.Parameter(typeof(string));
    var selector = "true && false";
    var parser = new System.Linq.Dynamic.Core.Parser.ExpressionParser(new[] { prm }, selector, new object[] {}, System.Linq.Dynamic.Core.ParsingConfig.Default);
    var expr = parser.Parse(null);

@zspitz
Copy link

zspitz commented Nov 22, 2020

Try the following:

  1. Close Visual Studio
  2. Delete the .vs folder in the root solution folder
  3. Delete all the bin and obj folders
  4. Reopen the solution

I did this and now && works in both Debug and Release mode.

@StefH StefH added the question label Nov 22, 2020
@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 22, 2020 via email

@StefH
Copy link
Collaborator

StefH commented Nov 26, 2020

Hello @Saeidasadi32,

See also this issue : #358

Your issue can be solved by adding this line to your Client WebAssembly project:

<BlazorWebAssemblyEnableLinking>false</BlazorWebAssemblyEnableLinking>

Or you can specify exactly what you want, see this link : https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/configure-linker?view=aspnetcore-3.1#control-linking-with-a-configuration-file

I applied this also to my example project here: BlazorAppHandlebarsExample

I probably have to add a Blazor WebAssembly section to the documentation to explain this scenario.

@StefH StefH changed the title "where" error in release mode Blazor WebAssembly : "where" error in release mode Nov 26, 2020
@Saeidasadi32
Copy link
Author

Saeidasadi32 commented Nov 26, 2020 via email

@StefH StefH closed this as completed Nov 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants