text:
GroupBy Query not optimal

Hi,
Given the sample code:
    namespace Entity
    {
        [Table("TbCli")]
        public sealed class TbCli
        {
            [Key]
            public int CdCli { get; set; }
            [Required]
            public string NmCli { get; set; }
        }
        [Table("TbRcd")]
        public sealed class TbRcd
        {
            [Key]
            public int CdRcd { get; set; }
            public int CdCli { get; set; }
            public DateTime DtRcdEmi { get; set; }
            public decimal VrRcdMer { get; set; }
        }
    }

    public class MyDbContext : DbContext
    {
        public DbSet<Entity.TbCli> TbCli { get; set; }
        public DbSet<Entity.TbRcd> TbRcd { get; set; }

        public MyDbContext(string nameOrConnectionString) : base(nameOrConnectionString)
        {
            Database.SetInitializer<DbContext>(null);
            this.Configuration.AutoDetectChangesEnabled = false;
            this.Configuration.LazyLoadingEnabled = false;
            this.Configuration.ProxyCreationEnabled = false;
            this.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
        }
    }

    public class MyResult
    {
        public int CdCli { get; set; }
        public string NmCli { get; set; }
        public decimal? VrRcdMer { get; set; }
        public bool DtRcdEmi { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            using (var _db = new MyDbContext(@"Data Source=..."))
            {
                var _md =
                    from cli in _db.TbCli
                    join cli_Rcd in _db.TbRcd on cli.CdCli equals cli_Rcd.CdCli into cli_Rcd_LeftJoin
                    from cli_Rcd in cli_Rcd_LeftJoin.DefaultIfEmpty()
                    select new
                    {
                        cli.CdCli,
                        cli.NmCli,
                        Rcd = new
                        {
                            cli_Rcd.CdRcd,
                            cli_Rcd.CdCli,
                            cli_Rcd.DtRcdEmi,
                            cli_Rcd.VrRcdMer,
                        },
                    };

                var _fd =
                    from _ in _md
                    group _
                    by new
                    {
                        CdCli = (_.CdCli),
                        NmCli = (_.NmCli),
                    }
                    into _grp
                    select new
                    {
                        CdCli = _grp.Key.CdCli,
                        NmCli = _grp.Key.NmCli,
                        VrRcdMer = (decimal?)_grp.Sum(cli => (cli.Rcd.DtRcdEmi >= new DateTime(2017, 1, 1, 0, 0, 0) && cli.Rcd.DtRcdEmi <= new DateTime(2017, 3, 31, 23, 59, 59)) ? cli.Rcd.VrRcdMer : 0),
                        DtRcdEmi = (_grp.Max(cli => (cli.Rcd.DtRcdEmi >= new DateTime(2017, 4, 1, 0, 0, 0) && cli.Rcd.DtRcdEmi <= new DateTime(2017, 6, 30, 23, 59, 59)) ? 1 : 0) == 1) ? true : false,
                    };

                Console.WriteLine(_fd);
                Console.WriteLine();

                DateTime Param_DataInicialDoValor = new DateTime(2017, 1, 1, 0, 0, 0);
                DateTime Param_DataFinalDoValor = new DateTime(2017, 3, 31, 23, 59, 59);
                DateTime Param_DataInicialDoFezCompras = new DateTime(2017, 4, 1, 0, 0, 0);
                DateTime Param_DataFinalDoFezCompras = new DateTime(2017, 6, 30, 23, 59, 59);

                _fd =
                    from _ in _md
                    group _
                    by new
                    {
                        CdCli = (_.CdCli),
                        NmCli = (_.NmCli),
                    }
                    into _grp
                    select new
                    {
                        CdCli = _grp.Key.CdCli,
                        NmCli = _grp.Key.NmCli,
                        VrRcdMer = (decimal?)_grp.Sum(cli => (cli.Rcd.DtRcdEmi >= Param_DataInicialDoValor && cli.Rcd.DtRcdEmi <= Param_DataFinalDoValor) ? cli.Rcd.VrRcdMer : 0),
                        DtRcdEmi = (_grp.Max(cli => (cli.Rcd.DtRcdEmi >= Param_DataInicialDoFezCompras && cli.Rcd.DtRcdEmi <= Param_DataFinalDoFezCompras) ? 1 : 0) == 1) ? true : false,
                    };

                Console.WriteLine(_fd);
                Console.WriteLine();

                Console.ReadKey();
            }
        }
    }

The first Console.WriteLine writes:
SELECT
[GroupBy1].[K1] AS [CdCli],
[GroupBy1].[K2] AS [NmCli],
[GroupBy1].[A1] AS [C1],
CASE WHEN (1 = [GroupBy1].[A2]) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C2]
FROM ( SELECT
    [Join1].[K1] AS [K1],
    [Join1].[K2] AS [K2],
    SUM([Join1].[A1]) AS [A1],
    MAX([Join1].[A2]) AS [A2]
    FROM ( SELECT
        [Extent1].[CdCli] AS [K1],
        [Extent1].[NmCli] AS [K2],
        CASE WHEN (([Extent2].[DtRcdEmi] >= convert(datetime2, '2017-01-01 00:00:00.0000000', 121)) AND ([Extent2].[DtRcdEmi] <= convert(datetime2, '2017-03-31 23:59:59.0000000', 121))) THEN [Extent2].[VrRcdMer] ELSE cast(0 as decimal(18)) END AS [A1],
        CASE WHEN (([Extent2].[DtRcdEmi] >= convert(datetime2, '2017-04-01 00:00:00.0000000', 121)) AND ([Extent2].[DtRcdEmi] <= convert(datetime2, '2017-06-30 23:59:59.0000000', 121))) THEN 1 ELSE 0 END AS [A2]
        FROM  [dbo].[TbCli] AS [Extent1]
        LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent2] ON [Extent1].[CdCli] = [Extent2].[CdCli]
    )  AS [Join1]
    GROUP BY [K1], [K2]
)  AS [GroupBy1]

The second Console.WriteLine writes:
SELECT
[Project3].[CdCli] AS [CdCli],
[Project3].[NmCli] AS [NmCli],
[Project3].[C1] AS [C1],
CASE WHEN (1 = [Project3].[C2]) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C2]
FROM ( SELECT
    [Project2].[CdCli] AS [CdCli],
    [Project2].[NmCli] AS [NmCli],
    [Project2].[C1] AS [C1],
    (SELECT
        MAX([Filter2].[A1]) AS [A1]
        FROM ( SELECT
            CASE WHEN (([Extent6].[DtRcdEmi] >= @p__linq__2) AND ([Extent6].[DtRcdEmi] <= @p__linq__3)) THEN 1 ELSE 0 END AS [A1]
            FROM  [dbo].[TbCli] AS [Extent5]
            LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent6] ON [Extent5].[CdCli] = [Extent6].[CdCli]
            WHERE ([Project2].[CdCli] = [Extent5].[CdCli]) AND ([Project2].[NmCli] = [Extent5].[NmCli])
        )  AS [Filter2]) AS [C2]
    FROM ( SELECT
        [Distinct1].[CdCli] AS [CdCli],
        [Distinct1].[NmCli] AS [NmCli],
        (SELECT
            SUM([Filter1].[A1]) AS [A1]
            FROM ( SELECT
                CASE WHEN (([Extent4].[DtRcdEmi] >= @p__linq__0) AND ([Extent4].[DtRcdEmi] <= @p__linq__1)) THEN [Extent4].[VrRcdMer] ELSE cast(0 as decimal(18)) END AS [A1]
                FROM  [dbo].[TbCli] AS [Extent3]
                LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent4] ON [Extent3].[CdCli] = [Extent4].[CdCli]
                WHERE ([Distinct1].[CdCli] = [Extent3].[CdCli]) AND ([Distinct1].[NmCli] = [Extent3].[NmCli])
            )  AS [Filter1]) AS [C1]
        FROM ( SELECT DISTINCT
            [Extent1].[CdCli] AS [CdCli],
            [Extent1].[NmCli] AS [NmCli]
            FROM  [dbo].[TbCli] AS [Extent1]
            LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent2] ON [Extent1].[CdCli] = [Extent2].[CdCli]
        )  AS [Distinct1]
    )  AS [Project2]
)  AS [Project3]

Why?
I expected something like:
SELECT
[GroupBy1].[K1] AS [CdCli],
[GroupBy1].[K2] AS [NmCli],
[GroupBy1].[A1] AS [C1],
CASE WHEN (1 = [GroupBy1].[A2]) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C2]
FROM ( SELECT
    [Join1].[K1] AS [K1],
    [Join1].[K2] AS [K2],
    SUM([Join1].[A1]) AS [A1],
    MAX([Join1].[A2]) AS [A2]
    FROM ( SELECT
        [Extent1].[CdCli] AS [K1],
        [Extent1].[NmCli] AS [K2],
        CASE WHEN (([Extent2].[DtRcdEmi] >= @p__linq__0) AND ([Extent2].[DtRcdEmi] <= @p__linq__1)) THEN [Extent2].[VrRcdMer] ELSE cast(0 as decimal(18)) END AS [A1],
        CASE WHEN (([Extent2].[DtRcdEmi] >= @p__linq__2) AND ([Extent2].[DtRcdEmi] <= @p__linq__3)) THEN 1 ELSE 0 END AS [A2]
        FROM  [dbo].[TbCli] AS [Extent1]
        LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent2] ON [Extent1].[CdCli] = [Extent2].[CdCli]
    )  AS [Join1]
    GROUP BY [K1], [K2]
)  AS [GroupBy1]

Why so different?
On my Database TbCli has 81104 rows and TbRcd has 7534828 rows
The first query takes 40secs to run and the second does not run at all... =(
I know there are some other ways of doing this query but for some reasons this is the best way for me right now...

@TanielianVB thanks for this great bug report! It seems that there is a limitation in the "aggregate pushdown" phase of the EF query plan compiler which prevents expressions containing any external references (including parameters) from being simplified. That is why you are seeing the version with the constants generating simpler SQL.
In general the bar for making changes in EF's plan compiler is very high given that there is a risk of functional and performance regressions which could be extremely hard for us to detect. Therefore I am leaning towards trying to help you find workarounds rather than attempting a fix or even leaving this issue open in the backlog for others to do it. That said, we would consider a well written PR which included risk mitigations, e.g. making this an opt in feature and adding good test coverage.
Possible workarounds

SqlQuery: Since you already know a way to figure out the SQL that you would want the LINQ query to generate and you have defined the result type for this query, it should be relatively easy to wrap the SQL in a call to SqlQuery() and passing the parameters, e.g.:

var results = _db.Database.SqlQuery<MyResult>(@"
    SELECT
    [GroupBy1].[K1] AS [CdCli],
    [GroupBy1].[K2] AS [NmCli],
    [GroupBy1].[A1] AS [C1],
    CASE WHEN (1 = [GroupBy1].[A2]) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C2]
    FROM ( SELECT
    	[Join1].[K1] AS [K1],
    	[Join1].[K2] AS [K2],
    	SUM([Join1].[A1]) AS [A1],
    	MAX([Join1].[A2]) AS [A2]
    	FROM ( SELECT
    		[Extent1].[CdCli] AS [K1],
    		[Extent1].[NmCli] AS [K2],
    		CASE WHEN (([Extent2].[DtRcdEmi] >= {0}) AND ([Extent2].[DtRcdEmi] <= {1})) THEN [Extent2].[VrRcdMer] ELSE cast(0 as decimal(18)) END AS [A1],
    		CASE WHEN (([Extent2].[DtRcdEmi] >= {2}) AND ([Extent2].[DtRcdEmi] <= {3})) THEN 1 ELSE 0 END AS [A2]
    		FROM  [dbo].[TbCli] AS [Extent1]
    		LEFT OUTER JOIN [dbo].[TbRcd] AS [Extent2] ON [Extent1].[CdCli] = [Extent2].[CdCli]
    	)  AS [Join1]
    	GROUP BY [K1], [K2]
    )  AS [GroupBy1]",
    Param_DataInicialDoValor,
    Param_DataFinalDoValor,
    Param_DataInicialDoFezCompras,
    Param_DataFinalDoFezCompras).ToList();

Query refactoring: After understanding the reason this query doesn't get simplified in the same way if you have parameters as if you use constants, I realized you should be able to write the query in such a way that the computation of the arguments of the aggregate functions occurs before the group by. I.e. project the values with the conditions first, then group, and in the end compute the aggregate functions. This code resulted in essentially the same LINQ query you are after:

DateTime Param_DataInicialDoValor = new DateTime(2017, 1, 1, 0, 0, 0);
DateTime Param_DataFinalDoValor = new DateTime(2017, 3, 31, 23, 59, 59);
DateTime Param_DataInicialDoFezCompras = new DateTime(2017, 4, 1, 0, 0, 0);
DateTime Param_DataFinalDoFezCompras = new DateTime(2017, 6, 30, 23, 59, 59);

var _md =
    from cli in _db.TbCli
    join cli_Rcd in _db.TbRcd on cli.CdCli equals cli_Rcd.CdCli into cli_Rcd_LeftJoin
    from cli_Rcd in cli_Rcd_LeftJoin.DefaultIfEmpty()
    select new
    {
        cli.CdCli,
        cli.NmCli,
        Rcd = new
        {
            cli_Rcd.CdRcd,
            cli_Rcd.CdCli,
            VrRcdMer = (cli_Rcd.DtRcdEmi >= Param_DataInicialDoValor && cli_Rcd.DtRcdEmi <= Param_DataFinalDoValor) ? cli_Rcd.VrRcdMer : 0,
            DtRcdEmi = (cli_Rcd.DtRcdEmi >= Param_DataInicialDoFezCompras && cli_Rcd.DtRcdEmi <= Param_DataFinalDoFezCompras) ? 1 : 0
        },
    };

var _fd =
    from _ in _md
    group _
    by new
    {
        CdCli = (_.CdCli),
        NmCli = (_.NmCli),
    }
    into _grp
    select new
    {
        CdCli = _grp.Key.CdCli,
        NmCli = _grp.Key.NmCli,
        VrRcdMer = (decimal?)_grp.Sum(cli => cli.Rcd.VrRcdMer),
        DtRcdEmi = _grp.Max(cli => cli.Rcd.DtRcdEmi) == 1,
    };

                Console.WriteLine(_fd);
                Console.WriteLine();

                Console.ReadKey();
            }
        }
    }

EF Triage: Repeating previous comment on the decision to not fix:
In general the bar for making changes in EF's plan compiler is very high given that there is a risk of functional and performance regressions which could be extremely hard for us to detect. Therefore I am leaning towards trying to help you find workarounds rather than attempting a fix or even leaving this issue open in the backlog for others to do it. That said, we would consider a well written PR which included risk mitigations, e.g. making the simplification an opt-in feature and adding good test coverage.

authors: TanielianVB divega


text:
Entity Data Model Designer crashes when selecting Navigation Properties

From VS Feedback:
When trying to select a navigation property the designer crashes with the message
Value cannot be null: parameter name font
at System.Windows.Window.set_DialogResult(System.Nullable`1)
at Microsoft.VisualStudio.Data.Tools.Package.SqlDebugger.SqlParametersDialog.okButton_Click(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.ReRaiseEventAs(System.Windows.DependencyObject, System.Windows.RoutedEventArgs, System.Windows.RoutedEvent)
at System.Windows.UIElement.OnMouseUpThunk(System.Object, System.Windows.Input.MouseButtonEventArgs)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventArgs.InvokeHandler(System.Delegate, System.Object)
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseTrustedEvent(System.Windows.RoutedEventArgs)
at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs, Boolean)
at System.Windows.Input.InputManager.ProcessStagingArea()
at System.Windows.Input.InputManager.ProcessInput(System.Windows.Input.InputEventArgs)
at System.Windows.Input.InputProviderSite.ReportInput(System.Windows.Input.InputReport)
at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr, System.Windows.Input.InputMode, Int32, System.Windows.Input.RawMouseActions, Int32, Int32, Int32)
at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr, MS.Internal.Interop.WindowMessage, IntPtr, IntPtr, Boolean ByRef)
at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

source: gharchive/issue

license: MIT

license_type: permissive

license_source: github-api


text:
#250 - remove excessive ToList calls in perfomance critical places

I checked main EntityFramework project for ToList calls, and replaced some of them. There are some more places to fix, but they need more careful editing.

@Backs,
Thanks for having already signed the Contribution License Agreement. Your agreement has not been validated yet. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

source: gharchive/pull-request

authors: Backs dnfclas


text:
Question: Generate migrations from code.

Hello, I'm trying to create a console app that tries to generate the migration code and detects if there are some operations that will be created in the generated code.
Ideally, if the dotnet ef migrations add <MigrationName> --json command would output the number of operations generated, that would be enough. A public API which returns a ReadOnlyList<MigrationOperation> like is passed to the CSharpMigrationOperationGenerator also will work. Is there some public API that I am missing? I am trying to fiddle with Microsoft.EntityFrameworkCore.Design.OperationExecutor, but the API seems too hard to use, and I am getting an error which says that the assembly is not found. I am trying to pass the same parameters as dotnet ef.
Any idea?

See this line in the database error page. It determines if there are any changes between the last migration and the current model.

Wow, your answer fits our needs perfectly. Thank you for the specific answer! 😄

authors: alexdrl bricelam

repo: aspnet/EntityFrameworkCore


text:
EF.Property called with wrong property on filter with subquery

Steps to reproduce
The following code
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp40
{
    class Program
    {
        static void Main(string[] args)
        {
            string nickname = "test";
            using var context = new TestContext();
            context.Reminders.Where(x => x.User == context.Nicknames.FirstOrDefault(n => n.Name == nickname).User).ToList();
        }
    }

    class TestContext : DbContext
    {
        public DbSet<Reminder> Reminders { get; set; } = null!;
        public DbSet<User> Users { get; set; } = null!;
        public DbSet<Nickname> Nicknames { get; set; } = null!;

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.EnableSensitiveDataLogging();
            optionsBuilder.UseSqlite(@"Data Source=database.sqlite");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<User>()
                .HasMany(x => x.Names)
                .WithOne(x => x.User);

            modelBuilder.Entity<Nickname>()
                .HasIndex(x => x.Name)
                .IsUnique();
        }
    }

    public class Reminder
    {
        public long Id { get; set; }
        public User? User { get; set; }
    }

    public class User
    {
        public long Id { get; set; }
        public virtual ICollection<Nickname> Names { get; set; } = null!;
        public Nickname? LastUsedName { get; set; }
    }

    public class Nickname
    {
        public long Id { get; set; }
        public string Name { get; set; }
        public User User { get; set; }
    }
}

produces this exception when trying to execute the query.
System.InvalidOperationException
  HResult=0x80131509
  Message=EF.Property called with wrong property name.
  Source=Microsoft.EntityFrameworkCore.Relational
  StackTrace:
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.TranslateSubquery(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)
   at Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression)
   at System.Linq.Expressions.BinaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ConsoleApp40.Program.Main(String[] args)

possibly a dupe of #18090
Further technical details
EF Core version: 3.0
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET Core 3.0
Operating system: Windows 10 Pro 1903
IDE: Visual Studio 2019 16.4 P1

@maumar to look for dupe and/or workaround.

related to/duplicate of #17852

https://github.com/aspnet/EntityFrameworkCore/issues/17852

I'm having a similar problem. Any progress on this?

authors: Crono1981 Suchiman ajcvickers itorian maumar


text:
How to make a SP call in EF core 3

I can't make a call with SP when I use EF core 3 using FromSQLRow.
It works in EF core 2 but not in EF core 3.
What approach should I go?

Please refer to https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#fromsqlsproc
If that does not resolve your question then please give us repro code.

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.
BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

authors: ajcvickers jt4000 smitpatel


text:
SqlLite in-memory database to retain while app is running

I need to use sqllite in-memory database while the app is running, right now it closes the connection after each call and the database is lost. This is useful for testing, but not so useful when one needs to have persistent sqllite in-memory database.
If I use in-memory connection string for SQLLite:
options.UseSqlite("Data Source=:memory:");

Then my init code fails:
public class InitDatabase: IInitDatabase {
    private readonly ApplicationDbContext db;
    public InitDatabase(ApplicationDbContext _db) {
        db = _db;
    }
    public void Init() {
        db.Database.EnsureCreated();
        db.Add(new ApplicationUser {
            Email = "test@example.com",
            UserName = "test"
        });
        db.SaveChanges();
    }
}

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) {
    // ...
    app.ApplicationServices.GetService<IInitDatabase>().Init();
}

According to other issue #4922 it closes the connection to database after EnsureCreated and then the memory is empty again.
My code works correctly with filebased SQLLite like this:
options.UseSqlite("Data Source=some.db");

Looks like a dupe of #4922

@ajcvickers sorry about that, thing is "sqllite memory" gives no open issues! Weird fulltext search.

@bricelam I reopened my issue #5086 and renamed it to mean what I meant: I want to have in-memory SqlLite database to persist while the app is running.

I reopen this, since what I want is a bit different: to persist in-memory database while app is running.

Found a solution to persistent in-memory SqlLite database, it was simple after all:

public class Startup
{
	private SqliteConnection inMemorySqlite;

	public void ConfigureServices(IServiceCollection services)
	{
		inMemorySqlite = new SqliteConnection("Data Source=:memory:");

		// ...
		services.AddDbContext<ApplicationDbContext>(options => {
			options.UseSqlite(inMemorySqlite);
		});
	}
}

_sqliteConnection.Open(); is needed when data-source is "in-memory".

authors: Ciantic ajcvickers amir734jj


text:
Create a page in docs to explain how we should handle migrations when targeting multi-databases providers

Create a page in docs to explain best practices with migrations when targeting multi-databases providers.
It sees difficult to handle, and migrations created for one provider doesn't work in the other.

I tried an example with the blogcontext from the docs.
It worth noticing that when we add 2 Providers and run the cli tool i get
public BloggingContext CreateDbContext(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder<BloggingContext>();

            //optionsBuilder.UseSqlite("Data Source=blog.db");
            optionsBuilder.UseSqlServer(EfFactoryOptions.ConnectionString); //.MaxBatchSize(1);
            optionsBuilder.UseMySql(EfFactoryOptions.MysqlConnectionString);
            //optionsBuilder.UseNpgsql(EfFactoryOptions.PostgreSqlConnectionString);

            return new BloggingContext(optionsBuilder.Options);
        }

System.InvalidOperationException: Services for database providers 'Microsoft.EntityFrameworkCore.SqlServer', 'Pomelo.EntityFrameworkCore.MySql' have been registered in the service provider. Only a single database provider can be registered in a service provider.
If possible, ensure that Entity Framework is managing its service provider by removing the call to UseInternalServiceProvider. Otherwise, consider conditionally registering the database provider, or maintaining one service provider per database provider.

So, you must go one provider at a time. And the sql server provider creates different migration from the mysql provider.
protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Blogs",
                columns: table => new
                {
                    BlogId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Url = table.Column<string>(type: "longtext", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Blogs", x => x.BlogId);
                });

            migrationBuilder.CreateTable(
                name: "Posts",
                columns: table => new
                {
                    PostId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    BlogId = table.Column<int>(type: "int", nullable: false),
                    Content = table.Column<string>(type: "longtext", nullable: true),
                    Title = table.Column<string>(type: "longtext", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Posts", x => x.PostId);
                    table.ForeignKey(
                        name: "FK_Posts_Blogs_BlogId",
                        column: x => x.BlogId,
                        principalTable: "Blogs",
                        principalColumn: "BlogId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Posts_BlogId",
                table: "Posts",
                column: "BlogId");
        }

protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Blogs",
                columns: table => new
                {
                    BlogId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    Url = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Blogs", x => x.BlogId);
                });

            migrationBuilder.CreateTable(
                name: "Posts",
                columns: table => new
                {
                    PostId = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    BlogId = table.Column<int>(type: "int", nullable: false),
                    Content = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Title = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Posts", x => x.PostId);
                    table.ForeignKey(
                        name: "FK_Posts_Blogs_BlogId",
                        column: x => x.BlogId,
                        principalTable: "Blogs",
                        principalColumn: "BlogId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Posts_BlogId",
                table: "Posts",
                column: "BlogId");
        }

In the end shoud be a migration per provider or something like this
protected override void Up(MigrationBuilder migrationBuilder)
        {
            if (migrationBuilder.ActiveProvider.Contains("MySql"))
            {
                //Pomelo.EntityFrameworkCore.MySql
                migrationBuilder.CreateTable(
                    name: "Blogs",
                    columns: table => new
                    {
                        BlogId = table.Column<int>(type: "int", nullable: false)
                            .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                        Url = table.Column<string>(type: "longtext", nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Blogs", x => x.BlogId);
                    });

                migrationBuilder.CreateTable(
                    name: "Posts",
                    columns: table => new
                    {
                        PostId = table.Column<int>(type: "int", nullable: false)
                            .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                        BlogId = table.Column<int>(type: "int", nullable: false),
                        Content = table.Column<string>(type: "longtext", nullable: true),
                        Title = table.Column<string>(type: "longtext", nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Posts", x => x.PostId);
                        table.ForeignKey(
                            name: "FK_Posts_Blogs_BlogId",
                            column: x => x.BlogId,
                            principalTable: "Blogs",
                            principalColumn: "BlogId",
                            onDelete: ReferentialAction.Cascade);
                    });

                migrationBuilder.CreateIndex(
                    name: "IX_Posts_BlogId",
                    table: "Posts",
                    column: "BlogId");
            }
            else if(migrationBuilder.ActiveProvider.Contains("SqlServer"))
            {
                //Microsoft.EntityFrameworkCore.SqlServer
                migrationBuilder.CreateTable(
                    name: "Blogs",
                    columns: table => new
                    {
                        BlogId = table.Column<int>(type: "int", nullable: false)
                            .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                        Url = table.Column<string>(type: "nvarchar(max)", nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Blogs", x => x.BlogId);
                    });

                migrationBuilder.CreateTable(
                    name: "Posts",
                    columns: table => new
                    {
                        PostId = table.Column<int>(type: "int", nullable: false)
                            .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                        BlogId = table.Column<int>(type: "int", nullable: false),
                        Content = table.Column<string>(type: "nvarchar(max)", nullable: true),
                        Title = table.Column<string>(type: "nvarchar(max)", nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_Posts", x => x.PostId);
                        table.ForeignKey(
                            name: "FK_Posts_Blogs_BlogId",
                            column: x => x.BlogId,
                            principalTable: "Blogs",
                            principalColumn: "BlogId",
                            onDelete: ReferentialAction.Cascade);
                    });

                migrationBuilder.CreateIndex(
                    name: "IX_Posts_BlogId",
                    table: "Posts",
                    column: "BlogId");
            }

@xrkolovos The approach you are taking is one valid approach, although in a lot of cases the code can be refactored so that only small parts of it are different for different providers--in some respects this is ideal since the migrations will remain mostly provider agnostic and common. However, there is no tooling support to do this for you--we have considered it, but it would be very expensive to make and at the moment we don't see enough people doing this for it to make the prioritization cut.
Another approach is to create two DbContext types that both derive from the same base. This can then be used to generate two parallel sets of migrations. Some people have factored this so the derived types are only used for migrations and at runtime the base type is used.
We'll keep this open to look at making the documentation better.

Are there any other ways to use different migration folders/namespaces etc. per provider? - so I could run the migration generation for multiple environments / configurations.
I'm looking at options to use SqLite for development environments and SQL Server for staging/production to enable fast inner loop development (no local sql server needed => clone&run experience on Mac/linux). SqLite is still better for that than the in-memory db just because it is persistent.

Have the same problem here! I'm looking for migrations to SqlServer and PostgreSQL in the same project. What is the better aproach?

Out for review: https://github.com/aspnet/EntityFramework.Docs/pull/563/files#diff-84500e94809956a7ede13c483140086e
Let us know what's missing.

@bricelam is that internal only? getting a forbidden error

Guess so. Updated to point to my branch.

Thanks. Looks very helpful! I guess an example of how to configure the subclassed context for DI wouldn't hurt (AFAIK if I register MySqliteDbContext, it wouldn't resolve MyDbContext instances when requested? I may be wrong on that)

Closing this as it is basically done. Any further requests for enhancements should be filed on the EF docs repo.

authors: MatheusM05 ajcvickers bricelam dasMulli xrkolovos


text:
Throw better exception message for client eval

Fixes #16133 and also partial fix for #15937
This is far from perfect and needs some further work. For example, see #17236
No issues reference #14935 any more; new issues cover things not fixed here but which were refeceing that issue.

Use null returning and base throwing would simplify code & also allow to print better message.
Every exception in query should not be printed as translation failed. Translation failure should only be printed when we fail to translate. We should discuss this.
I did not look at all the tests, but are all tests which are not throwing exception right now which were disabled with client eval in past are enabled in this PR?

Unable to process Expression in visitor. + thing about using AsEnumerable etc.

Going to merge this now, then work on the feedback in a separate PR.

@smitpatel @divega Messages for the two general cases:

The LINQ expression '{expression}' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly, for example by by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(), if this is appropriate. See https://go.microsoft.com/fwlink/?linkid=2101038 for more detailed information.

Processing of the LINQ expression '{expression}' failed. This may indicate either a bug or limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101038 for more detailed information.

With two different fwlinks?
Thoughts?

Also include visitor name in 2nd exception message. LGTM otherwise.

@roji - I commented on all the why not translated comments. If you see any other test which you think we should translate then, please file an issue with the test name and what should be the translation.

The new fwlink for the "processing the linq expression failed" case is https://go.microsoft.com/fwlink/?linkid=2101433.

@smitpatel realistically we should probably just do a pass later and search for translation failure assertions in tests, I don't think there's anything urgent in there for 3.0 (at least not that I can tell).

Nothing urgent. I meant to say whenever you decide to do pass or see something out of place. That is true even without regards of client eval changes.

authors: ajcvickers divega roji smitpatel


text:
Problem with walking inheritance chain

Currently we have a BeforeAction event listener. In this listener, we have our own IActionDescriptor which currently it has a few properties like DisplayName and Id. This is all as you would expect.
I was looking what other data I could get and started to poke around at underlying data. When doing this, I noticed that the actual type in most cases is ControllerActionDescriptor. So as a test, I added ControllerName to my IActionDescriptor. I was expecting that if this property exists somewhere in the inheritance chain of the underlying type it would bring it across and if it doesn’t (i.e. the object is FooActionDescriptor that inherits from ActionDescriptor and hence doesn’t have ControllerName) it would leave it alone. Currently it doesn’t bring across ControllerName, even though its on the underlying type.

I think I know what the problem is. In TelemetrySourceAdapter we have the following - the important part being the GetType(). Because we a leveraging GetType() here, it means that its going to base the rest of the logic off what the compile time definition was and not what the runtime object actually contains.
With the caching that we are doing, I'm imaging that it makes things harder, but it would be infinity more useful if it could cater for this case, otherwise I have to drop back to type checking to get the required data and at that point I have to take on dependencies on those type.

Thinking about it... I'm guessing that the caching could still work, it would just need to based off the actual types that it sees going by. If the only type it saw was ControllerActionDescriptor then it would only have a mapping from it to my type. If it saw ControllerActionDescriptor and FooActionDescriptor, it would have a cached mapping for both.

We're going to address this by basing each top level item off of the dynamic type of the object. Deeper down in the object graph, you'll have to generate a proxy dynamically by calling into the proxy factory.

Agreed on plan

f90c31c7d47278ab163990120eb1ac2183cf6764

authors: avanderhoorn rynowak

repo: aspnet/EventNotification


text:
Different casing in variables causes exception

Case
Add the same configuration key value pair to from different configuration sources using different casing.
Expected result
Configuration value from last configuration source is the value present in the final configuration.
The documentation states that

Configuration keys are not case-sensitive

and

Configuration sources are read in the order that they're specified. In the preceding code, the environment variables are read last. Any configuration values set through the environment replace those set in the two previous providers.

Actual result
ArgumentException with the message An item with the same key has already been added is thrown.

Sample program
var configurationRoot = new ConfigurationBuilder()
    .AddInMemoryCollection(new Dictionary<string, string>
        {
            {"CASE:PROBLEM", "black magic"}
        })
    .AddInMemoryCollection(new Dictionary<string, string>
        {
            {"case:PROBLEM", "white magic"}
        })
    .Build();

var newconfigurationRoot = new ConfigurationBuilder()
    .AddInMemoryCollection(configurationRoot.AsEnumerable())
    .Build();

Fixed by https://github.com/aspnet/Extensions/pull/503

authors: ajcvickers rasmus

repo: aspnet/Extensions


text:
StyleCop Returns?

Ok, so we've had our encounters with StyleCop in the past, but I think there may be some value in it. StyleCop is now a set of Roslyn Analyzers and Code Fixes. This is a (possibly crazy) PR that adds it to our repo and enables a single rule. @davidfowl 's favorite rule in fact, SA1000: KeywordsMustBeSpacedCorrectly.
If we believe this is a terrible idea, I'll go away, but I don't think it's the best use of our time to have code reviewers nit picking things like spacing, var usage, license headers, etc. If we want to try it further, I can enable a few more core rules and see where that takes us. I can also bring it to aspnet/AspNetCore.
StyleCop has a lot of rules but it is also very configurable. If we are cautious and introduce rules that mostly already align with what we intend as style conventions, I think this will add value. The goal is not to reshape our code around some specific style guidance but to use robots to check style adherance instead of spending code review time and iterations on it.
These errors show up in command-line builds:

And in VS (where they can also be Ctrl-.ed away):

Thoughts? @davidfowl @rynowak @Eilon

cc @aspnet/build for new dependency if we decide to try this out :)

You should add code coverage first 😉

Failing the build for style errors is evil so I don't support this, at all...

You should add code coverage first 😉

Failing the build for style errors is evil

Explain?

I think issues like this are better solved with editor config like rules that light up in the IDE rather than build failures. Style errors just aren't important enough to have people pushing new commits to PRs and waiting an hour (or however long it takes tests to build and tests to pass). We don't have a problem with people writing code in the right style (except you and spaces between things 😄 ), we don't however have code coverage 😄

I think we should add .editorconfig and dotnet-format and then enable something like this based on what that supports.
I want to avoid having discussions about minor style issues that there's no debate over. @JamesNK follows me around and tells me about every extra blank line I've ever created. That matters to some people and they aren't wrong, but I have a lower sensitivity to it. I agree with him in principle, but I don't want to spend time on it. It's much better for the system to fix it more me.
I'm open to trying anything once, and I have a clear idea of what I think success looks like - less time spent by the team on trivial stuff.
I like more ideas like having a minimal editorconfig and an agreement that it should be respected (using VS code cleanup + dotnet-format). I like the most ideas like having a bot to auto-format the world nightly and send a PR.

I think we should add .editorconfig and dotnet-format and then enable something like this based on what that supports

I looked in to dotnet-format and wasn't super happy with what I saw (very limited functionality, it just does whitespace reformatting as far as I could tell). It doesn't support most of the editorconfig options right now. Still, it's a start.

Style errors just aren't important enough to have people pushing new commits to PRs and waiting an hour (or however long it takes tests to build and tests to pass).

This is actual feedback. Thanks. Though a "nit" comment about a style issue tends to yield exactly the same result. If all the feedback is "nit"s like this would you expect someone to update the PR?

except you and spaces between things

I'm open to trying anything once, and I have a clear idea of what I think success looks like - less time spent by the team on trivial stuff.

This is what I'm going for. I find style "nits" tend to be unhelpful and trivial. I think it's a waste of the reviewers time when automation can take care of it.

I like more ideas like having a minimal editorconfig and an agreement that it should be respected (using VS code cleanup + dotnet-format). I like the most ideas like having a bot to auto-format the world nightly and send a PR.

I'm on board with something like that. It got shot down last time so I thought it wasn't generally an option we were interested in.

I'm on board with something like that. It got shot down last time so I thought it wasn't generally an option we were interested in.

I think this is worth a revisit. What's great about me is that I'm willing to change my mind. Maybe other people want to be great too.

Here's what dotnet-format yields on Extensions (with no changes to our existing editorconfig): https://github.com/aspnet/Extensions/compare/anurse/dotnet-format?expand=1
There are definitely some... interesting things in our code ;).
It does look like dotnet-format is considering work on supporting more editorconfig options but right now there's no need to add any for that purpose since we use the default for all the options dotnet-format supports. There's value in doing it for VS scenarios though.

Check that thing in.

Failing the build for style errors is evil so I don't support this, at all... I'm supporting of using it at IDE time though.

+1. TS with SignalR had (has?) it cranked up to that max that the build would fail on the smallest infraction.
An .editorconfig would be useful because it tells Roslyn what do when refactoring, e.g. _underscoreFields

TS with SignalR had (has?) it cranked up to that max that the build would fail on the smallest infraction.

Working with SignalR's TS client recently, and I really appreciated the linter failing the build.

Style errors just aren't important enough to have people pushing new commits to PRs and waiting an hour (or however long it takes tests to build and tests to pass).

I think this is a straw man. We just need to make sure both local builds fail and PR checks fail quickly for style errors. No one expects changes that fail to even build locally to pass our PR checks, right?

If you can make it fail local builds only, that’d be more ok. Still let’s start with an editor config

authors: JamesNK anurse davidfowl halter73 rynowak


text:
Is it possible to use Power-BI-Embedded-report with Asp.net core ?

Hi All,
Is it possible to use Power-BI-Embedded-report with asp.net core ?
BR
Michal

I just tried and got stuck bringing in Microsoft.PowerBI.Core. Looks like it depends on System.IdentityModel.Tokens.Jwt.

does anyone have a fix or know how to get around this issue? if not then i going to create a web api in another web app and call then when i need it. not pretty but the only way i can think of working around this issue.

I struggled also with this task (November 2016). I ended up with two separate web applications. First our asp.net core application with a link to the PowerBi Report which is hosted in a dedicated asp.net web application.

This issue is being closed because it has not been updated in 3 months.
We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

repo: aspnet/Home


text:
Got the following error after publishing to Azure App Service

Hi My project can be published and worked on IIS.
However after I published it to Azure App Service, I got the following error in the event log. The static content can be accessed without any problem.
</Data><Data>http://primeobjects.azurewebsites.net/search/cloudknowledge/latest/?count=10&needmediaurl=false</Data><Data>/search/cloudknowledge/latest/</Data><Data>216.40.101.89</Data><Data></Data><Data>False</Data><Data></Data><Data>IIS APPPOOL\PrimeObjects</Data><Data>12</Data><Data>IIS APPPOOL\PrimeObjects</Data><Data>False</Data><Data>   at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException)
</Data></EventData></Event><Event><System><Provider Name="ASP.NET 4.0.30319.0"/><EventID>1309</EventID><Level>2</Level><Task>0</Task><Keywords>Keywords</Keywords><TimeCreated SystemTime="2015-08-19T20:24:27Z"/><EventRecordID>1213452359</EventRecordID><Channel>Application</Channel><Computer>RD000D3A313E67</Computer><Security/></System><EventData><Data>3005</Data><Data>An unhandled exception has occurred.</Data><Data>8/19/2015 8:24:27 PM</Data><Data>8/19/2015 8:24:27 PM</Data><Data>f93e2b6750554f1ca2fbea07ff3ab0a3</Data><Data>1</Data><Data>1</Data><Data>0</Data><Data>/LM/W3SVC/1199578095/ROOT-5-130844894678138322</Data><Data></Data><Data>/</Data><Data>D:\home\site\wwwroot\</Data><Data>RD000D3A313E67</Data><Data></Data><Data>14216</Data><Data>w3wp.exe</Data><Data>IIS APPPOOL\PrimeObjects</Data><Data>DirectoryNotFoundException</Data><Data>Unable to find the runtime directory 'D:\home\site\wwwroot\..\approot\runtimes\dnx-clr-win-x86.1.0.0-beta6'.
Possible causes:
1. The runtime was not packaged with the application.
2. The packaged runtime architecture is different from the application pool architecture.
   at AspNet.Loader.Bootstrapper.LoadApplication(String appId, String appConfigPath, IProcessHostSupportFunctions supportFunctions, LoadApplicationData* pLoadAppData, Int32 loadAppDataSize)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Web.Hosting.ProcessHost.System.Web.Hosting.IProcessHostLite.ReportCustomLoaderError(String appId, Int32 hr, AppDomain newlyCreatedAppDomain)
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)   at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException)

</Data><Data>http://primeobjects.azurewebsites.net/search/cloudknowledge/latest/?count=10&needmediaurl=false</Data><Data>/search/cloudknowledge/latest/</Data><Data>216.40.101.89</Data><Data></Data><Data>False</Data><Data></Data><Data>IIS APPPOOL\PrimeObjects</Data><Data>12</Data><Data>IIS APPPOOL\PrimeObjects</Data><Data>False</Data><Data>   at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException)
</Data></EventData></Event></Events>

Are any of those 2 possible reasons valid?

Possible causes:

The runtime was not packaged with the application.
The packaged runtime architecture is different from the application pool architecture.

authors: PrimeObjects davidfowl


text:
Updating kvm scripts on home/master

@suhasj

:shipit:

authors: Praburaj suhasj


text:
Enabled xml doc generation

@NTaylorMullen

Hi @ajaybhargavb, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!
The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.
TTYL, DNFBOT;

:shipit:

authors: Eilon ajaybhargavb dnfclas

repo: aspnet/HtmlAbstractions


text:
Design proposal for configuration for registry

Here's a straw man to discuss for the design of retrieving policies from
the registry for IHttpClientFactory.
Goals:

Keep simple usage simple
Support updates (opt in)
Allow use of policies by name and with code
Allow dynamism (choosing policy based on request)

Non-goal:

Avoid overloading based on Func<> types with same arity. This is a
destructive case for intellisense and should be avoided.

/cc @reisenberger @joelhulen @stevejgordon @martincostello @bryanjhogan

I've addressed all of the minor feedback here. Planning to add tests tomorrow

Updated and added tests. I converted the existing builder tests into end-to-ends.

repo: aspnet/HttpClientFactory


text:
How to know if RememberMe was checked for the cookie

There are cases where we loose the rememberMe information about the user when we regenerate the cookie.
eg. If you change the password, then we regenerate the cookie and we have no way of knowing whether the user had selected the rememberMe option

c251bf0162091730b6cc74d97731db74d98e499d

authors: HaoK rustd

repo: aspnet/Identity


text:
'Get' in type Kestrel.Http.Frame does not have an implementation error on startup

I know whenever someone says "nothing changed" we all roll our eyes, so I'm sure that isn't the case, but yesterday afternoon I started getting the error below after updating some classes and viewmodels.
I've gone back in source control to the last two checkins previous, both of which were working fine prior to yesterday afternoon and they both fail too. I've checked my project.json file, but none of the nuget packages have changed for at least a week, which was the first thing I thought of.
System.Reflection.ReflectionTypeLoadException was unhandled by user code
  HResult=-2146232830
  Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
  Source=mscorlib
  StackTrace:
       at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
       at System.Reflection.RuntimeAssembly.get_DefinedTypes()
       at Microsoft.AspNet.Hosting.Server.ServerLoader.LoadServerFactory(String assemblyName)
       at Microsoft.AspNet.Hosting.Internal.WebApplication.EnsureServer()
       at Microsoft.AspNet.Hosting.Internal.WebApplication.BuildApplication()
       at Microsoft.AspNet.Hosting.Internal.WebApplication.Initialize()
       at Microsoft.AspNet.Hosting.WebApplicationBuilder.Build()
       at Revelar.Startup.Main(String[] args) in c:\code\RevelarPortalSolution\src\RevelarMVC\Startup.cs:line 120
  InnerException:

#LOADER EXCEPTION#
{"Method 'Get' in type 'Microsoft.AspNet.Server.Kestrel.Http.Frame`1' from assembly 'Microsoft.AspNet.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.":"Microsoft.AspNet.Server.Kestrel.Http.Frame`1"}

This occurs on the Startup Main
// RC2 Version - Entry point for the application.
        public static void Main(string[] args)
        {
            var application = new WebApplicationBuilder()
                .UseConfiguration(WebApplicationConfiguration.GetDefault(args))
                .UseStartup<Startup>()
                .Build();

            application.Run();
        }

project.json
{
  "commands": {
    "web": "RevelarMVC",
    "ef": "EntityFramework.Commands"
  },
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "EntityFramework.Commands": "7.0.0-rc2-16649",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-rc2-16649",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc2-16216",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc2-16405",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc2-16304",
    "Microsoft.AspNet.Mvc": "6.0.0-rc2-16770",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc2-16770",
    "Microsoft.AspNet.Hosting": "1.0.0-*",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc2-16236",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc2-16107",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc2-16051",
    "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc2-16221",
    "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc2-15952",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-15952",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc2-15948",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-15958",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-15958",
    "Microsoft.Extensions.Logging.Debug": "1.0.0-rc2-15958",
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16530",
    "Microsoft.Framework.DependencyInjection.Abstractions": "1.0.0-rc1-15644",
    "Microsoft.Framework.OptionsModel": "1.0.0-rc1-15642",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc2-16226",
    "System.ComponentModel.Annotations": "4.1.0-rc2-23623",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc2-16069",
    "Microsoft.AspNet.Server.Kestrel.Https": "1.0.0-rc2-16236"
  },

  "frameworks": {
    "dnx451": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],

  "publishExclude": [
    "**.user",
    "**.vspscc"
  ],
  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
  },
  "userSecretsId": "aspnet5-WebApplication1-167835da-fd4b-498e-958f-a8c586dbf38d",
  "version": "1.0.0-*"
}

hosting.json
{
  "server": "Microsoft.AspNet.Server.Kestrel",
  "environment": "Development",
  "detailedErrors": true
}

Doesn't matter if I run with "web" or "IISExpress"
project file is set to use 1.0.0-rc2-16312
I also tried updating the DI and OptionsModel packages to rc2 in the Microsoft.Extensions namespace which is where it looks like they've moved. That didn't help - and since the error is specific to Kestrel and it has been working for the last week as-is I didn't expect it to.
Any ideas?

I was able to fix this by uninstalling the Kestrel package and then reloading it with "Dependency Behavior - Highest Patch" checked in nuget package manager.
This updated the Microsoft.AspNet.Hosting package to rc2-16161 rather than -16150 that was specified as the minimum.
So this issue can be closed, but would first appreciate a comment on if the aspnet team thinks we should be using "highest patch" or "lowest" for dependency behavior in nuget when working with this bleeding edge rc2 stuff? Lowest has always worked up until now.

We use 1.0.0-* dependencies for all of our RC2 work and you may need to as well if you're updating often.

thanks

authors: Tratcher esargent

repo: aspnet/KestrelHttpServer


text:
Add doc comments to all KestrelServerOptions properties

There are currently a few undocumented properties in KestrelServerOptions. This pretty visible as far as Kestrel APIs are concerned, so it might be worth adding before 1.0.
@Eilon @muratg

@halter73 please enlist help from @cesarbs as needed.

Anything planned here? Need to get this done today, or it'll have to wait.

@halter73 How busy are you with other things? I can take this.

@cesarbs I had already started on this. Please feel free to make/suggest improvements to the PR. A thorough review would be greatly appreciated.

authors: Eilon cesarbs halter73 muratg


text:
[Not for merging] IStreams

Requires too much upstream working HttpAbstractions; and then everywhere :-/

Though frame changes using this and supporting FrameDuplexStream changes would cut the above allocs from 640,000 bytes to 160,000 bytes for 4k requests; a 75% reduction in allocation.

Did you open this PR so you could reference it in your "Stream - Interface segregation" issue and "Value Tasks PR"? Should we close this for now?


text:
Unify the path comparer for relative path and absolute path.

To make code cleaner, need to unify the path comparer for relative path (RelativePathEqualityComparer.cs) and absolute path in FileHelper.cs file.

may not need it now as not using the absolute path equality comparer now.

repo: aspnet/LibraryManager


text:
Make restore faster by copying files

Compared to the original implementation of reading files in from the cache and writing them back out to the destination, a simple file copy seems to be several times faster on average.

Using similar measurements as in #538, but without clearing the cache (i.e. test measures just copying files from cache to project folder).  The test libraries:

Test Size
Provider
Library used
# files
Size

Medium
JSDelivr
jquery@3.4.1
234
1,416,263

Large
JSDelivr
@fortawesome/fontawesome-free@5.11.2
1631
10,636,759

X-large
JSDelivr
devextreme@19.1.5
2018
144,183,992

Baseline (2.0.96 CLI tool):

Test
Trial 1
2
3
4
5

Medium
2.78
2.64
2.72
2.56
2.67

Large
15.94
15.9
16.83
23.83
15.94

X-Large
51.7
51.27
50.58
51.72
50.82

Results after change (private build):

Test
Trial 1
2
3
4
5

Medium
0.77
0.77
0.76
1.04
0.86

Large
2.63
2.66
2.6
2.5
2.75

X-Large
3.2
3.12
3.19
3.21
3.11

One big caveat on the performance numbers I posted above: I'm finding that performance varies by a factor of about 2x just between running the tool as a DLL (dotnet libman.dll restore) vs. as a CLI tool (libman restore).  I did mix those up during my testing, which could account for some (but not all!) of the delta.  I'll try to follow up with the SDK folks about this next week.


text:
fix #90: ResourceStringLocalizerFactory creates string localizer based on resourcetype's name instead of full name

cc @DamianEdwards, @Eilon

Nice work @kirthik

After the small comment, :shipit:

merged 90116ddd78a8a9f3e5e5ba68500b799e9dc3ec8b

authors: Eilon hishamco kirthik

repo: aspnet/Localization


text:
RouteAttributes do not combine on inherited classes

I'd suggest (and after a hint where to start, I'd also plege to implement it as PR), that RouteAttributes from subclasses should be combined:
[Route("v1")]
public class Version1BaseController : Controller { }

[Route("some")]
public class SomeOtherBaseController : Version1BaseController { }

[Route("[Controller]"]
public class FooController : SomeOtherBaseController {
    public string Bar() { return "Hello World" }
}

Now I'd expect the Action to be here: http://localhost/v1/some/foo/bar,
but actual it is here: http://localhost/foo/bar
Would you consider to allow that in AttributeBased Routing?
Is it already allowed and I'm just not able to see how?
If not: Is there advice how to accomplish that?

@rynowak / @lodejard I thought we did this on purpose, but I can't recall why. Do you happen to remember?

Btw - your code does support overwriting the whole route in the combineAttributeRoutes Method, by checking for startswith / or ~/ - so opting-out is easy, but opting-in is not possible. But I'd be happy to hear the reasoning behind that

It seems odd to create a base class to prepend something to the path. What if I want to inherit from a class, but I don't want to follow the same routing pattern?
Inheritance or route attributes is supported (in my mind at least) for the cases where you have a group of controllers fulfilling a common role (MyApiController) with a common routing pattern, and usually also a set of common base functionality. It's also a convenience that was carried over from previous versions (this time with [controller] syntax instead of genuine conventional routing).
Usually if you're doing this, you have a common base-class for the whole app, or one for APIs and one for Browser-based actions.
We also didn't want to make routing too strongly tied to class identity, which is why we only use attribute routes on the most derived class to define any - in other words, routes on a controller class have overriding behavior.

@glatzert - have you thought about implementing this using namespaces and something like https://github.com/aspnet/Entropy/blob/dev/samples/Mvc.CustomRoutingConvention/NameSpaceRoutingConvention.cs
Attribute routing is already meta-programmable to a complete extent. I'd rather not add more default behaviors if there's not a strong reason why it's relevant to most users.

@rynowak thanks for the clearification. If I understood you right, I could also do something like:
[Route("v1/some/[Controller]")]
public class SomeOtherBaseController : Controller { }

public class FooController : SomeOtherBaseController {
    public string Bar() { return "Hello World" }
}

And would archieve more or less, what I wanted?
But I'll also take a look into the custom conventions - that seems reasonable.
Thank you

Yes, that example would work

authors: Eilon glatzert rynowak

repo: aspnet/Mvc


text:
After updating ( 1.1 to 2.0 )  the StaticFiles can't be found in the root path.

Question:
1、
project:    webapi core1.1
nuget:     Microsoft.AspNetCore.StaticFiles
file:          wwwroot/Index.html
ok:          "http://xxxxx/Index.html" return "hello world"
operation: right-click "Controller Folder" --> "Add(D)" --> "controller(T)" --> select any and "Add".
error:       "http://xxxxx/Index.html" return "http://xxxxx/Index.html/".
2、
project:   webapi core 1.1
nuget:     Microsoft.AspNetCore.StaticFiles
file:          wwwroot/Index.html
ok:          "http://xxxxx/Index.html" return "hello world"
operation: update to core2.0
error:       "http://xxxxx/Index.html" return "http://xxxxx/Index.html/".

Can you provide a sample that worked before that now fails?  Preferably a github repository.

Hi David:
Here is the github repository.  #6665.

Just for future reference so you know how to diagnose these issues. Turn logging on to a high verbosity level like trace or debug:
Change this line
https://github.com/NMSLanX/WebApi_6665/blob/3f2a5c8603e0803efa6c328a8b8d878a4d189d59/Error/Actual/WebApiOne/WebApiOne/Startup.cs#L46
To:
loggerFactory.AddConsole(LogLevel.Trace);

The log immediately shows the problem:
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:64780/Index.html/
dbug: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[5]
      The request path /Index.html/index.html does not match an existing file

I ran the WebApiOne project under Error. It seems like it 404s without the upgrade to 2.0, are you sure it's related?
Also, I'm not sure this has anything to do with MVC.

This issue was moved to aspnet/StaticFiles#210

authors: Eilon NMSLanX davidfowl


text:
Revive skipped CacheTagHelper based tests

Updating to the 2.2 SDK causes (nearly all) tests involving CacheTagHelper to fail. While we're waiting for https://github.com/aspnet/Common/commit/388c04ce5cb242865c432c481b23b85e14c7ce68 to propogate, we'll skip these tests. Related issue: https://github.com/aspnet/Mvc/issues/6985

PR to revive: 2a9c4444b4c3694499a96e68a416e23b67c02fd6


text:
Enable analyzers

This is exploratory PR.
I understand that this is a bit too many pragmas.
One of the ideas I had was to add something to mark "Known exposable pubternal type" and stop analyzer from firing on it.
Thoughts? Ideas?

Can you ignore types with .Internal in their namespace for pubternal? (I assume they all do?)

Can you ignore types with .Internal in their namespace for pubternal? (I assume they all do?)

This analyzer specifically tries to find types with Internal in their namespace exposed through public types.

Agree with @rynowak - this is super nice. This should be good to go once you fix up the attribute. If you'd like to get this in and follow up cleaning up the suppression around attributes, that should be fine.

Removed checks from attributes.

authors: benaadams pakrym pranavkm


text:
Cleanup legacy services in favor for CodeAnalysis.Razor alternatives

Today we have copies of several of our public API services in Microsoft.VisualStudio.LanguageServices.Razor. We should remove those and export the newer variants of those from Microsoft.CodeAnalysis.Razor.Workspaces.

[x] EditorSettingsManager
[x] RazorIndentationFactsService
[x] RazorSyntaxFactsService
[x] TagHelperCompletionService
[x] TagHelperFactsService
[x] Internalize RazorTemplateEngineFactoryService, TagHelperResolver, RazorDiagnosticJsonConverter
[x] Delete RazorEditorParser

44a47182b229ef998c9e520eb5d3a4f5d8c7fae1
de23788019fc83400be7f60335eed6032c60162c
44e58740290f8622f8f83ecf7c3ff5c7728b64b6
44b4bf6bc607a3748feb6b1b8a91c42b5e539579
520876e55d3bb86d90b3bf22e4c71db07283dd58
458111ad03c8b46a8a1ebab472f3b23f845415c3
6cf78ceb1bbdfd0a8d573925f09fd540f5f146c1

repo: aspnet/Razor


text:
Error - Referencing C# in Script Class Body

In a <script> block in a RazorPage, using @ errors when inside a class body. It works fine inside the constructor .
I'm templating some script in my pages using C# and @. In most places, using @xxx will render text. It errors in VS when used inside the body of a JavaScript Class.
// Somewhere
ViewContext.ViewData.Add("Foo", "Bar")

// Works
<script>
    @ViewContext.ViewData["Foo"]
    class TestClass {  }
</script>

// Works
<script>
    class TestClass {
         constructor() {
             @ViewContext.ViewData["Foo"]
         }
    }
</script>

// Error - Unexpected Token
<script>
    class TestClass {
        @ViewContext.ViewData["Foo"]
    }
</script>

Thanks for reporting this issue, @RandyBuchholz.
@NTaylorMullen, can you please look into this?

@mkArtakMSFT NP. Quick aside.
I wanted to ping an item related( to @)
In Page
@{ var green = "green"; }
<style>
   .colorizer{ background-color: @green; }
</style>

This used to kill Intellisense and formatting. A release or two ago (I think) Intellisense started prompting the var. But the whole style block is still all white (or black) text, and formatting (ctrl-K-D) doesn't work on the block. Curious if you had any status on this. I didn't want to open a new issues as I think there a couple already.
Thanks --RB

@RandyBuchholz, there have been several styling /coloring related issues, which the folks owning it are on top of. I have no info regarding the one specific you're referring to.

Hey @RandyBuchholz could you share more of the View? I'm not seeing your error (also worked without the @{}):

@NTaylorMullen,
I'm on 2.1.300-preview2-008533 and have ReSharper.
VisualStudio.15.Preview/15.7.0-pre.4.0+27617.1 Installed Version: Community
Microsoft .NET Framework Version 4.7.03056
Created a new Web Application w/https, no authentication. Replaced Index content only.

@RandyBuchholz I think you must have some other extension installed that's doing that to your document. Following the same repro as you did I get:

Cool, thanks for checking it out.

authors: NTaylorMullen RandyBuchholz mkArtakMSFT


text:
Multiple OIDC handlers will get in each others way.

Considering the case where a user has two OIDC Middleware each with a different authority and hence different config (keys, issuer, etc).
One will fail, possibly triggering an update to the IDP for new config, throw, add error logs, etc.  The other will succeed. Depends on who gets the message first.
We need a way for a MW to know it should handle the signin message.
Solutions could be as simple as using state to add logic: "yes" this is for me. This means crypto for each MW. A "dispatcher / router" or "handlers multiplexing options", etc .. at this layer seems complicated.

Isn't each oidc MW instance having is own authenticationScheme sufficient?

This is handled fine by all the other middlewares today, this should just work...

It's fine for challenges, the collision occurs on the (optional) callback path. The other middelware would have the same problem. You either need to set unique callback paths or implement the MessageReceived and manually filter them.

@brentschmaltz out of curiosity, why not using CallbackPath (or setting an explicit RedirectUri) to make sure your multiple OIDC middleware don't collide?
@HaoK fine is probably not the most appropriate term :smile:
I realized there were actually a few traps when working on the new OpenID 2.0 middleware for ASP.NET 5 yesterday.
Consider this snippet:
app.UseOAuthAuthentication("Scheme1", options => {
    options.Caption = "Caption1";
    options.ClientId = "ClientId1";
    options.ClientSecret = "ClientSecret1";
    options.AuthorizationEndpoint = "AuthorizationEndpoint1";
    options.TokenEndpoint = "TokenEndpoint1";
});

app.UseOAuthAuthentication("Scheme2", options => {
    options.Caption = "Caption2";
    options.ClientId = "ClientId2";
    options.ClientSecret = "ClientSecret2";
    options.AuthorizationEndpoint = "AuthorizationEndpoint2";
    options.TokenEndpoint = "TokenEndpoint2";
});

app.Run(async context => {
    foreach (var scheme in context.Authentication.GetAuthenticationSchemes()) {
        await context.Response.WriteAsync($"{scheme.AuthenticationScheme}: {scheme.Caption}");
    }
});

It will work just fine (GetAuthenticationSchemes will return a description for both Scheme1 and Scheme2), thanks to the first parameter, that sets ConfigureOptions.Name.
But this snippet will miserably fail and only return the options used for the first Google middleware:
app.UseGoogleAuthentication(options => {
    options.AuthenticationScheme = "Scheme1";
    options.Caption = "Caption1";
    options.ClientId = "ClientId1";
    options.ClientSecret = "ClientSecret1";
    options.AuthorizationEndpoint = "AuthorizationEndpoint1";
    options.TokenEndpoint = "TokenEndpoint1";
});

app.UseGoogleAuthentication(options => {
    options.AuthenticationScheme = "Scheme2";
    options.Caption = "Caption2";
    options.ClientId = "ClientId2";
    options.ClientSecret = "ClientSecret2";
    options.AuthorizationEndpoint = "AuthorizationEndpoint2";
    options.TokenEndpoint = "TokenEndpoint2";
});

app.Run(async context => {
    foreach (var scheme in context.Authentication.GetAuthenticationSchemes()) {
        await context.Response.WriteAsync($"{scheme.AuthenticationScheme}: {scheme.Caption}");
    }
});

Of course, this can be fixed using the second parameter (that sets the options instance name), but it's not terribly obvious for a beginner, specially for those who used this pattern with Katana.

Yeah that pain point is well known to me since I ran into (and is what prompted named options in the first place).  If you have any suggestions on how to improve that scenario, definitely willing to make it better.  Its super hard to discover today, even if you were to look at identity code which is the only one that relies on this, its super subtle and easy to miss...

The issue is actually in the sugar methods, they are implicitly providing "Google"/option names which is why if you don't specify the name, they collide.

@HaoK, actually, I wonder if we shouldn't simply stop retrieving the options from the DI when using the app.Use*Authentication extensions that take an explicit delegate. Why not simply instantiate the options in the extension and manually flow it to the middleware's constructor?

We could certainly stop using IOptions for middlewares, as not all of them do, but there's a consistency issue there where Options are sometimes singletons then, and sometimes instances...  Probably should rename them to be Settings and not options just to disambiguate that they aren't like the rest of the options in the framework...

@Tratcher yes the issue is on the way in. In fact un-initiated login updates may occur.
@PinpointTownes it has been my experience that forcing users to have a separate path is a non-starter for some as the IDP may already have registered the redirect_uri.

This is no longer an issue because we require a callback path now, so each middleware can have its own path.

authors: HaoK PinpointTownes Tratcher brentschmaltz

repo: aspnet/Security


text:
Added support for git.push, git.pullrequest.created, and git.pullrequest.updated.

Added support for git.push, git.pullrequest.created, and git.pullrequest.updated to VSTS Receiver.  Also added related tests.

Hi @jproefrock, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@jproefrock, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.
Thanks, DNFBOT;

Let me know if there are any issues with this pull request. I would love to see this in the pre release nuget package.

It's in: 3f0f4cb8a380792a236968ea775e9a4330ea7245 :)
Thanks!
Henrik

authors: HenrikFrystykNielsen dnfclas jproefrock

repo: aspnet/WebHooks

license_source: bigquery


text:
aspnetboilerplate - User Session in web api using token based authentication

In normal web api,   I am getting user info and ClaimsIdentity using custom authorization filter   by header authorization token,
string token = filterContext.Request.Headers.GetValues("Authorization").First();
var accessToken = token.Replace("Bearer ", "");
var userInfoClient = new UserInfoClient(new Uri(Constants.UserInfoEndpoint), accessToken);
var userInfoResponse = await userInfoClient.GetAsync();
Then I call    ClaimsIdentity cidentity = (ClaimsIdentity)claimsIdentity;
var loginResult = await GetLoginResultAsync(email, "123qwe", "xxx", cidentity);
CurrentUnitOfWork.SetTenantId(loginResult.Tenant.Id);
I am getting tenant id and user id from loginresult. But session user is always null.
How Can I get current user as current session user?
Visual studio 2015,.net frame work 4.7 and ABP version V2.1.3

Have you tried injecting AbpSession and use it's properties ?

authors: Noushida ismcagdas

repo: aspnetboilerplate/module-zero

license: mit


text:
Installation is broken

Installing the program with:
pip install asposecloud

and then trying to import the module, as suggested in the documentation,
>>> import asposecloud
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named asposecloud

fails.  Looking at what is installed in ~/.virtualenvs/test/lib/python2.7/site-packages/asposecloud , it appears there is no __init__.py file installed into the main directory.  The setup.py file needs to be fixed so that it installs the bits inside of the asposecloud directory.
Though I see tests included in this repository, I can't believe that they are working if the library itself is not importable.  I suspect that one of the following is true:

The tests are not being run automatically on each commit and/or before each release,
The tests are being run, but they are being run against the source tree (which does have an __init__.py file in the right place); so they aren't picking up that the installed library is broken; or
The tests are being run on an installed version of the library, but it is being installed in such a way that it only overwrites changed files, it doesn't delete files that have been removed.

I suggest:

The tests should be run automatically by a CI system on each commit.
The first step in the test should be to create a brand new virtual environment into which only asposecloud is installed.
When the tests are executed, the source tree should not be in the path.

I wouldn't normally write such a long issue here, but reinstalling this module broke my running application, which is pretty annoying since I pay for the cloud API service.  Please fix this ASAP.

Hello
Did you update the package or it happend after uninstall and then reinstall the same release.
I'm looking into the issue.
Thanks

Merged and updated the package.

authors: assadvirgo quietlyconfident


text:
Obtaining tokens from GAE returns CURLE_OPERATION_TIMEOUTED

This is displayed as output:
[4844:4870:0811/003604:ERROR:nss_util.cc(842)] After loading Root Certs, loaded==false: NSS error code: -8018
This is from the log:
[0.040993] TID=0: BEGIN: Getting tokens from GAE proxy
[5.556198] TID=0: Retrying (1/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5515 milliseconds\n")
[12.131752] TID=0: Retrying (2/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5514 milliseconds\n")
[20.063387] TID=0: Retrying (3/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5512 milliseconds\n")
[29.630514] TID=0: Retrying (4/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5512 milliseconds\n")
[43.500967] TID=0: Retrying (5/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5515 milliseconds\n")
[65.971463] TID=0: Retrying (6/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5511 milliseconds\n")
[103.853738] TID=0: Retrying (7/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5512 milliseconds\n")
[174.118715] TID=0: Retrying (8/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5514 milliseconds\n")
[307.998735] TID=0: Retrying (9/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5513 milliseconds\n")
[570.559934] TID=0: Retrying (10/10) get_tokens after exception: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5515 milliseconds\n")
[1088.956387] TID=0: Error during get_tokens after 10 attempts: Failure("Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5512 milliseconds\n")

Looks like you have problems connecting to the authorization endpoint. Are you behind a proxy?

No proxy, have no problems doing the authorization from the browser, it's only the CLI utilities that have issues. Tried refreshing all ocaml components.

The authorization proxy is at: https://gd-ocaml-auth.appspot.com. Check if you can reach it via browser and via curl (from the command line $ curl https://gd-ocaml-auth.appspot.com should return some HTML). Otherwise if it's a problem of net latency, you can try raising the timeout in the config file (connect_timeout_ms).

Same issue here:
# time curl -I https://gd-ocaml-auth.appspot.com
HTTP/1.1 200 OK
Date: Fri, 21 Oct 2016 04:43:02 GMT
Expires: Fri, 21 Oct 2016 04:53:02 GMT
Cache-Control: public, max-age=600
ETag: "6EjDMA"
X-Cloud-Trace-Context: 7a80774c8626fc81e415015b1c579df1
Content-Type: text/html
Server: Google Frontend
Content-Length: 2455
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32"

real   	0m5.885s
user   	0m0.060s
sys    	0m0.010s

# cat /root/.gdfuse/me/gdfuse.log
[0.000287] TID=0: Setting up me filesystem...
[0.000314] TID=0: Loading configuration from /root/.gdfuse/me/config...done
[0.000406] TID=0: BEGIN: Saving configuration in /root/.gdfuse/me/config
[0.000527] TID=0: END: Saving configuration in /root/.gdfuse/me/config
[0.000570] TID=0: Loading application state from /root/.gdfuse/me/state...done
Current version: 0.5.24
Setting up cache db...done
Setting up CURL...done
[23.222566] TID=0: Error during request: Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5534 milliseconds

[23.222589] TID=0: Retrying (1/10)
[30.067578] TID=0: Error during request: Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5544 milliseconds

[30.067601] TID=0: Retrying (2/10)
[38.590850] TID=0: Error during request: Code: 28, Description: CURLE_OPERATION_TIMEOUTED, ErrorBuffer: Resolving timed out after 5542 milliseconds

[38.590862] TID=0: Retrying (3/10)

If it happens again, you should raise connect_timeout_ms (for example to 10000).

authors: astrada buffyg davidneudorfer

repo: astrada/google-drive-ocamlfuse


text:
[red-knot] circular references in class definitions panic

class C(list[C]): ...

the above code causes red_knot to panic, due to something a bit subtle:

We query for the type of C via infer_definition_types
during this process we infer the type of list[C]
during that process we (correctly!) annotate the type of list and stuff it in the inference expressions
We then try to get the type of C... and call infer_definition_types

This leads to C being infered of type Unknown thanks to infer_definition_types_cycle_recover, which is fine and great... but due to something I don't quite understand, the result of infer_definition_types_cycle_recover ends up being the final definition of infer_definition_types(C).
As a result we lose the inference on list! So later linting code that traverses the AST tries to look up the type of the list expression and blows up.
My understanding here is that the queries are like:
infer_definition_types(C) -> infer_definition_types(C)
--------------------------------------------------------
infer_definition_types(C) -> [C: Unknown]
--------------------------------------------------------
[C: ClassType (base: Unknown), expressions: {list} ]

but that  future queries to the DB for infer_defintion_types(C) ends up returning [C: Unknown]. I have been reading the docs on salsa cycling a bit on this point to try and decipher what is going on here but maybe somebody else would have a better understanding of what can be done here.

@carljm's working on fixpoint iteration that will allow cyclic dependencies

Alright, good to know! I had this intuition that I didn't need general fixed point iteration (just not caching the cycle recovery result for definitions), but trying to db.report_untracked_read my way out of this got me nowhere.
Will studiously wait on this one for the adults to show up with the principled solution when the time is right.

Salsa's current cycle handling intentionally sets the "cycle fallback" result as the result for every query in the cycle, not just the single query that finally triggered the cycle. This is done for determinism reasons (so that results don't change depending on where you happen to enter a cycle.) I think this behavior explains the result you're seeing.
For the code you posted, I would expect it to work in a stub file (where class bases are deferred) but not in a regular Python file, where they are eagerly evaluated.
Salsa's current cycle recovery is not very useful for us, which is why I'm working on the fixpoint iteration feature, which we definitely need, for example, for evaluating types in loopy control flow graphs.

authors: MichaReiser carljm rtpg

repo: astral-sh/ruff


text:
Concerning assert (S101) example and the change of >

When using the assertion assert(S101), changing from x > 0 to x <= 0 can be confusing because these statements might have different meanings.
x <= 0 checks if x is less than or equal to zero, while x > 0 checks if x is greater than zero.
For example, if x is -1, then x <= 0 is true, but x > 0 is false. On the other hand, if x is 1, then x <= 0 is false, but x > 0 is true.
https://github.com/astral-sh/ruff/blob/25c374856a57c3a58fdbd2b347ed656fd30fd9c0/crates/ruff/src/rules/flake8_bandit/rules/assert_used.rs#L19-L28

Hi!
Since the if statement will raise an error if the expression is true and an assert will raise an error if the expression is false this should be working as intended.
Would you prefer the documentation called this out explicitly? Or used if not x > 0:?

@zanieb Thank you very much!
I agree with you! Although the information is technically the same, it can be difficult to understand just by quickly reading through the documentation. Your suggestion of using if not x > 0 is helpful because it highlights the main point for the reader.oid using the assert condition, which is how I understand the documentation.

No problem!
I think including an if not ... example is clearer. We can retain the existing example after an "or..." if we want. Want to contribute? :)

Based on the suggestions for refactoring found at https://github.com/sourcery-ai/sourcery/wiki/Current-Refactorings#de-morgan-identity, it appears that you may be introducing morgan-identity-cause. So I would refer to the optional "or..."

authors: Anselmoo zanieb


text:
Remove deprecated parsing list functions

Summary
This PR removes the deprecated parsing list functions and updates the references to use the new functions.
There are now 4 functions to accommodate this pattern. They are divided into 2 groups: one to parse a sequence of elements and the other to parse a sequence of elements separated by a comma. In each of the groups, there are 2 functions: one collects and returns all the parsed elements as a vector and the other delegates the collection part to the user. This separation is achieved by using Fn and FnMut to allow mutation in the later case.
The error recovery context has been updated to accommodate the new sequence kind. Currently, the terminator token kinds only contain the necessary token to end the list and not necessarily the ones which might help in error recovery. This will be updated as I go through the testing phase. This phase is basically coming up with a bunch of invalid programs to check how the parser is acting and how can we help in the recovery phase.
Test Plan
Currently, my plan is to keep the testing part separate than the actual update. This doesn't mean I'm not testing locally, but it's not thorough. The main reason is to keep the diffs to a minimal and writing test cases will require some effort which I want to decouple with the actual change. This is ok here as it's not getting merged into main but the parser PR.

Clippy says that at_expr_end isn't used but it'll be used at a later stage. So, ignore that for now. There are no other clippy errors apart from this.