Tag: .net core

在.NET Core中引用时,从程序集文件加载的类型不等于相同的类型

我获取一个Type ,查询其程序集位置,然后从同一地址加载程序集,并从加载的程序集中找到相同的类型。 结果类型不等于原始类型。 这是测试用例: [TestMethod] public void TestTypeLoadingWithFilePath() { var originalType = typeof(SomeClass); var assemblyAddress = originalType.Assembly.Location; var loadedAssembly = Assembly.LoadFile(assemblyAddress); Assert.IsNotNull(loadedAssembly); var loadedType = loadedAssembly.GetType(originalType.FullName); Assert.IsNotNull(loadedType); Assert.AreEqual(originalType, loadedType); } 最后一个断言测试失败。 这仅发生在Windows上的.NET Core上。 (我正在测试最新版本,2.1.4)。 但.NET Framework不是这种情况。 我的问题是: 这是设计还是错误? 如果是设计,为什么? 同样,如果它是设计的,这是不是意味着.NET Standard的两个实现之间的不同行为? (.NET Core与.NET Framework)

.Net Core 2.0 Process.Start抛出“指定的可执行文件不是此OS平台的有效应用程序”

我需要使用与用户Windows上关联的这两种文件类型的任何可执行文件自动执行.reg文件和.msi文件。 .NET Core 2.0 Process.Start(string fileName)docs说:“文件名不需要表示可执行文件。它可以是任何扩展名已与系统上安装的应用程序相关联的文件类型。” 然而 using(var proc = Process.Start(@”C:\Users\user2\Desktop\XXXX.reg”)) { } //.msi also 给我 System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform. at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start(String fileName) 使用ErrorCode和HResult -2147467259,以及NativeErrorCode 193。 相同的代码在.Net Framework 3.5或4控制台应用程序中起作用。 我不能指定精确的exe文件路径作为方法的参数,因为用户的环境是变体(包括Windows版本)并且不受我的控制。 这也是为什么我需要将程序移植到.Net Core,尝试使其作为SCD控制台应用程序工作,以便不需要安装特定的.Net Framework或.NET Core版本。 Visual Studio调试运行和发布为win-x86 SCD时都会抛出exception。 […]

AddOAuth linkedin dotnet core 2.0

我正在使用dotnet核心我想在网站上设置LinkedIn身份validation,因为LinkedIn没有默认身份validation构建器,因为facebook,google和twitter我决定使用如下通用实现: services.AddAuthentication().AddOAuth(“LinkedIn”, c => { c.ClientId = Configuration[“linkedin-app-id”]; c.ClientSecret = Configuration[“linkedin-app-secret”]; c.Scope.Add(“r_basicprofile”); c.Scope.Add(“r_emailaddress”); c.CallbackPath = “/signin-linkedin”; c.AuthorizationEndpoint = “https://www.linkedin.com/oauth/v2/authorization”; c.TokenEndpoint = “https://www.linkedin.com/oauth/v2/accessToken”; c.UserInformationEndpoint = “https://api.linkedin.com/v1/people/~:(id,formatted-name,email-address,picture-url)”; }) 我有一个问题,因为GetExternalLoginInfoAsync()为null,查看Identity ASP.net核心源,是因为providerkey为null。 取自asp.net核心代码: var providerKey = auth.Principal.FindFirstValue(ClaimTypes.NameIdentifier); var provider = items[“LoginProvider”] as string; if (providerKey == null || provider == null) { return null; } 问题是我在哪里可以将ClaimTypes.NameIdentifier添加到LinkedIn声明?

使用LinqKit PredicateBuilder进行相关模型(EF Core)

我想使用LinqKit的PredicateBuilder并将谓词传递给相关模型的.Any方法。 所以我想构建一个谓词: var castCondition = PredicateBuilder.New(true); if (movies != null && movies.Length > 0) { castCondition = castCondition.And(c => movies.Contains(c.MovieId)); } if (roleType > 0) { castCondition = castCondition.And(c => c.RoleId == roleType); } 然后使用它来过滤与谓词中的模型有关的模型: IQueryable result = _context.Name.AsExpandable().Where(n => n.CastInfo.Any(castCondition)); return await result.OrderBy(n => n.Name1).Take(25).ToListAsync(); 但这会导致System.NotSupportedException: Could not parse expression ‘n.CastInfo.Any(Convert(__castCondition_0, Func“2))’: The given […]

正确的方式来签署.net核心组件

我正在尝试签署一个.net核心库,我只是不确定我是否做得正确 1)使用VS Command Promp我叫sn -k mykey.snk 2)将mykey.snk复制到myproject文件夹 3)在project.json添加了密钥文件 “frameworks”: { “netstandard1.6”: {} }, “buildOptions”: { “outputName”: “MyLib”, “keyFile”: “mykey.snk” } 这是正确的,库(dll)是否可以在.net核心和完整.net 4.6应用程序上使用?

为什么最终用户必须注销两次?

我试图让IdentityServer4在新的.NET Core 2.1应用程序中运行(它在.NET Core 2.0应用程序中完美运行)。 我尝试过以下方法: 1)下载此项目,即IdentityServer4应用程序: https : //github.com/ghstahl/IdentityServer4-Asp.Net-2.1-Identity-Examples/tree/e0aeeff7e078aa082c8e16029dd2c220acc77d7b 2)使用Identity Server4应用程序下载此项目,即MVC应用程序: https : //github.com/IdentityServer/IdentityServer4.Samples/tree/dev/Quickstarts/6_AspNetIdentity/src/MvcClient 。 3)将两个项目添加到同一解决方案中。 MVC项目使用IdentityServer项目进行身份validation; 授权等 我不得不做出以下改变: 1)更改为IdentityServer应用程序中包含的Startup(AddIdentityServer现在接受参数): services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = “/Identity/Account/Login”; options.UserInteraction.LogoutUrl = “/Identity/Account/Logout”; }) 2)配置IdentityServer应用程序以侦听端口5000并在身份服务器上禁用SSL。 除了注销工具外,一切都按预期开箱即用。 当我在MVC应用程序中单击注销时; 在MVC应用程序中调用以下代码: public async Task Logout() { await HttpContext.SignOutAsync(“Cookies”); await HttpContext.SignOutAsync(“oidc”); } 然后,用户将重定向到IdentityServer应用程序中的Logout.cshtml。 但是,他们必须再次单击注销(在IdentityServer应用程序上)才能实际注销,即他们在MVC应用程序中单击注销(第二点),然后在IdentityServer中注销(第一点)。 为什么最终用户必须注销两次?

在单独的项目Asp.net Core MVC中进行本地化

我刚刚升级到Rc2,而以前的工作不再适用。 我在一个单独的项目中有几个resx文件,我使用自定义类来访问数据。 现在运行时出现以下错误: MissingManifestResourceException:找不到适合指定文化或中性文化的任何资源。 确保在编译时将“GarageWeb.Core.CoreResources.resources”正确嵌入或链接到程序集“GarageWeb.Core”中,或者所有所需的附属程序集都是可加载和完全签名的。 编辑:我简化了这一点,并创建了一个控制台应用程序,除了重现错误所需的一切,所以除去了所有内容: https : //github.com/GarageWeb/ResourceTest 这是访问资源的类: public class ResourceService : IResourceService { private readonly ILoggingService _loggingService; private readonly ICoreGlobalResourceService _coreGlobalResources; private readonly ISiteGlobalResourceService _siteGlobalResources; public ResourceService(ILoggingService loggingService, ICoreGlobalResourceService coreGlobalResourceService, ISiteGlobalResourceService siteGlobalResources) { _loggingService = loggingService; _coreGlobalResources = coreGlobalResourceService; _siteGlobalResources = siteGlobalResources; } public string GetGlobalText(string resourceKey, bool includeBrackets = true) { […]

VS 2017 .NET Core BinaryFormatter

是否在.NET Core工具中发布了VS 2017包含的BinaryFormatter? 当我创建.NET Core控制台应用程序时,我找不到BinaryFormatter。 有许多Nuget包,但哪一个是正确的,可以使用.NET Core获得一个有效的BinaryFormatter? 顺便说一句,使用已发布的Visual Studio创建一个无法编译的项目有点尴尬。 我需要启动我的.NET Core控制台应用程序所在的cmd shell并执行操作 dotnet restore 让它编译。 我在参考菜单中错过了VS命令吗? EDIT1 使用Install-Package BinaryFormatter给了我一个例外 PM> Install-Package BinaryFormatter Restoring packages for d:\source\vc17\NetCoreApp\ConsoleApp1\ConsoleApp2\ConsoleApp2.csproj… Install-Package : Package BinaryFormatter 1.0.2 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package BinaryFormatter 1.0.2 supports: – dnx451 (DNX,Version=v4.5.1) – dnxcore50 (DNXCore,Version=v5.0) At line:1 char:1 + Install-Package BinaryFormatter + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ […]

将ArrayPool对象提供给JsonOutputFormatter构造函数

从.net RC2升级到RTM后,我发现需要为从ArrayPool派生的JsonOutputFormatter的构造函数提供参数。 我如何获得此对象? 我正在手动创建JsonOutputFormatter,因为我需要配置ReferenceLoopHandling。 我能找到的其他相关信息是这样的: https : //github.com/aspnet/Mvc/issues/4562 public IServiceProvider ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMemoryCache(); services.AddSession(); services.AddMvc(); var formatterSettings = JsonSerializerSettingsProvider.CreateSerializerSettings(); formatterSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; JsonOutputFormatter formatter = new JsonOutputFormatter(formatterSettings, ???); services.Configure(options => { options.OutputFormatters.RemoveType(); options.OutputFormatters.Insert(0, formatter); }); //etc… }

是否支持.NET Core中的Microsoft.AspNet.WebApi.Client?

我目前正在尝试使用.NET Core和MediaTypeFormatters中的HttpClient进行一些JSON格式化。 特别是函数“ReadAsAsync(…,MediaTypeFormatter,…)”( https://msdn.microsoft.com/de-de/library/system.net.http.httpcontentextensions.readasasync(v=vs.118) .aspx )在HttpContent-Class的.NET Framework中可用,会非常有用。 据我所知,它可以在NuGet包中找到Microsoft.AspNet.WebApi.Client但我无法下载它,因为它在.NET Core中不受支持。 虽然我已经读过,但它应该是: HttpContent.ReadAsAsync在哪里? https://www.techrepository.in/consuming-rest-api-methods-in-net-core-mvc-application 我知道可以使用Newtonsoft等进行格式化。 但有人知道,如果那个软件包有一天会再次在.NET Core中提供吗? 我真的找不到任何信息…… 谢谢