It's too bad that demo is quite outdated. I'll dig in, though any assistance would be helpful.
We're trying to optimize some specific app service layer code, but we're having a hard time getting a console app setup with BenchmarkDotNet to get started. Has anyone setup someting similar that we can take a look at?
We have an app service that's doing quite a bit of manipulation and we're hoping to resolve that app service in the benchmark app so we can compare one method "Evaluate" of the app service to another, like "OptimizedEvaluate".
Hmm, this sort of thing works if I apply it directly to the action method in question - but I can't seem to place this generally so that I don't need to markup everything to fix this:
public class LocalizationPipeline
{
public void Configure(IApplicationBuilder applicationBuilder)
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr")
};
var options = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(
culture: "en-US",
uiCulture: "en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
};
options.RequestCultureProviders = new[]
{ new RouteDataRequestCultureProvider() {
Options = options } };
applicationBuilder.UseRequestLocalization(options);
}
}
/// <summary>
/// Load Modal when segment is clicked on.
/// </summary>
/// <param name="model">The Segment View Model from the ajax call</param>
/// <returns></returns>
[MiddlewareFilter(typeof(LocalizationPipeline))]
public async Task<PartialViewResult> ViewSegmentModal(SegmentModalViewModel model)
{
// some work
}
In our solution, we're only supporting english and french (ontario standard).
I sort of understand though I'm surprised that localization would have an effect in model binding. Is that expected? Is there any documentation about that effect?
We've developed a system using aspnetzero, works great. We're now down to testing other features that we didn't pay much attention to, like localization. We have a case where a modal popup works fine when the language is English, and fails (model binding with the view model, my guess) when the language is anything but english.
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - There are 6 validation errors:
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (PrimaryOpacities)
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (PrimaryOpacities)
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (PrimaryOpacities)
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (SecondaryOpacities)
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (SecondaryOpacities)
WARN 2020-12-03 15:46:05,850 [64 ] Mvc.ExceptionHandling.AbpExceptionFilter - The value '0.2' is not valid. (SecondaryOpacities)
INFO 2020-12-03 15:46:05,851 [64 ] c.Infrastructure.ControllerActionInvoker - Executed action PatientManagement.Web.Areas.App.Controllers.PatientsController.ViewSegmentModal (PatientManagement.Web.Mvc) in 609.1147ms
INFO 2020-12-03 15:46:05,851 [64 ] ft.AspNetCore.Routing.EndpointMiddleware - Executed endpoint 'PatientManagement.Web.Areas.App.Controllers.PatientsController.ViewSegmentModal (PatientManagement.Web.Mvc)'
ERROR 2020-12-03 15:46:05,852 [64 ] nostics.DeveloperExceptionPageMiddleware - An unhandled exception has occurred while executing the request.
Abp.Runtime.Validation.AbpValidationException: Method arguments are not valid! See ValidationErrors for details.
at Abp.Runtime.Validation.Interception.MethodInvocationValidator.ThrowValidationError()
at Abp.Runtime.Validation.Interception.MethodInvocationValidator.Validate()
at Abp.AspNetCore.Mvc.Validation.AbpValidationActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at StackifyMiddleware.RequestTracerMiddleware.InvokeAsync(HttpContext context)
at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware`1.InvokeAsync(HttpContext context) in /_/src/Transports.AspNetCore/GraphQLHttpMiddleware.cs:line 50
at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 121
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext)
at NWebsec.AspNetCore.Middleware.Middleware.MiddlewareBase.Invoke(HttpContext context)
at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
INFO 2020-12-03 15:46:05,915 [12 ] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished HTTP/1.1 POST http://localhost:63114/App/Patients/ViewSegmentModal application/x-www-form-urlencoded;+charset=UTF-8 434 - 500 - text/html;+charset=utf-8 685.3018ms
I know it says there are model violations, but it doesn't necessarily make sense here.
Here's the english XHR request:
The view model is pretty simple:
public class SegmentModalViewModel
{
// other fields
public double[] PrimaryOpacities { get; set; }
public double[] SecondaryOpacities { get; set; }
}
Hmm, what does this look like actually? Same problem, different oauth provider (of my own writing):
I do know that I'll have to do something here to Request.Host to stop grabbing the subdomain since the provider only passes the callback path.
https://github.com/Clinical-Support-Systems/oneid-oauth-middleware/blob/9ece0e71be0a70371f9d0de78ae8144ec00f502e/src/AspNet.Security.OAuth.OneID/OneIdAuthenticationHandler.cs#L398
Perhaps something like this:
Uri request = new Uri("http://subdomain.domain.co.uk");
string host = request.Host;
string hostWithoutPrefix = null;
var tlds = new List<string>()
{
//the second- and third-level TLDs you expect go here, set to null if working with single-level TLDs only
"co.uk"
};
if (tlds != null)
{
foreach (var tld in tlds)
{
Regex regex = new Regex($"(?<=\\.|)\\w+\\.{tld}$");
Match match = regex.Match(host);
if (match.Success)
hostWithoutPrefix = match.Groups[0].Value;
}
}
//second/third levels not provided or not found -- try single-level
if (string.IsNullOrWhiteSpace(hostWithoutPrefix))
{
Regex regex = new Regex("(?<=\\.|)\\w+\\.\\w+$");
Match match = regex.Match(host);
if (match.Success)
hostWithoutPrefix = match.Groups[0].Value;
}
But, do you know of a code example of including this in the query string and/or state so that I can redirect back to the right tenancy (with subdomain)?
Actually, it does appear possible to do without doing that by resolving services at runtime:
var patientAppServiceType = Type.GetType("PatientManagement.Patients.PatientsAppService, PatientManagement.Application");
var patientAppService = _iocManager.IocContainer.Resolve(patientAppServiceType) as IPatientsAppService;
var result = AsyncHelper.RunSync(() => patientAppService.GetPatientForViewAsync(patientId));
We have now been able to circumvent Telerik's inability to use their report designer on netstandard/netcore projects. I have a version based off the demo that I can share as well.
So, I know that Telerik Reporting has been asked about here before but I'm so close and I just need a nudge. For some unknown reason, Telerik doesn't have the ability to have a Net Core reporting project (something to do with System.Drawing) but you can create a .NET 4.8 project, add the reports and then view those reports from a Net Core 3.1 app. I have that all working. My problem now is DI.
The Core project is Net Core, the Application project is Net Core but the reporting project can only reference NetStandard.
I do have a module for the reporting project that the Mvc then depends on, the report is correctly being resolved using IocManager:
/// <summary>
/// See https://docs.telerik.com/reporting/knowledge-base/how-to-inject-custom-dependency-in-reports-controller-of-dot-net-core-application
/// </summary>
/// <param name="report"></param>
/// <param name="operationOrigin"></param>
/// <param name="currentParameterValues"></param>
/// <returns></returns>
public ReportSource Resolve(string report, OperationOrigin operationOrigin, IDictionary<string, object> currentParameterValues)
{
var reportType = Type.GetType(report);
if (reportType == null) throw new UserFriendlyException($"Could not find a corresponding report for type '{report}'.");
var resolvedReport = (Report)_iocManager.IocContainer.Resolve(reportType);
var reportSource = new InstanceReportSource { ReportDocument = resolvedReport };
return reportSource;
}
But, now that I can view the report - how can I get data from the system?
So, what are the possibilities here?
I don't know how to reproduce this. All we do to reproduce is build, then make any change whatsoever to any .cshtml file and try and browse the site - 100% fail.
I was able to work around this by simply updating Microsoft.CodeAnalysis.Common from 3.6.0 to 3.7.0-3.final.
With the last few updates, our team is finding that any change to razor causes the next load of the page to throw an exception. This is causing development to slow way down as we have to build every single time we make small changes.
It should be configured as it always has been and yes, debug constant is on in this context:
services.AddControllersWithViews(options =>
{
options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
})
#if DEBUG
.AddRazorRuntimeCompilation()
#endif
.AddNewtonsoftJson();
Raw exception:
System.TypeLoadException: Method 'CommonGetMetadataReference' in type 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' from assembly 'Microsoft.CodeAnalysis.CSharp, Version=3.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not have an implementation.
at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.ProcessCore(RazorCodeDocument codeDocument)
at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Process(RazorProjectItem projectItem)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.CompileAndEmit(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler.OnCacheMiss(String normalizedPath)
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Razor.Compilation.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet`1 expirationTokens, String relativePath, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultAsync>g__Logged|21_0(ResourceInvoker invoker, IActionResult result)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at GraphQL.Server.Transports.AspNetCore.GraphQLHttpMiddleware`1.InvokeAsync(HttpContext context)
at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 105
at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
at IdentityServer4.Hosting.MutualTlsTokenEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Abp.AspNetZeroCore.Web.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Any ideas?
Microsoft.CodeAnalysis.Common was at v3.6.0