小编Nig*_*888的帖子

在VS2017中定位特定的.NET Core运行时版本

我在Visual Studio 2015中成功创建并部署了.NET Core应用程序。尽管VS2015中对.NET Core的工具和支持正在消失,所以我决定从VS2017重新开始。但是,我遇到的问题是版本控制。我的托管服务提供商正在运行Plesk〜v12,并且仅支持一些运行时间,而且绝对不支持最新和最长时间。

在VS2015中,project.json我可以通过修改所有依赖项来定位特定的运行时版本,但是我看不到如何在Visual Studio 2017中执行此操作。我的主持人回答说,它们支持“ 1.0.3”(当前版本为1.04) NET Core 1.0应用程序中的最新SDK),以及.NET Core 1.1应用程序中的“ 1.1.0和1.1.1”。(最新版本的SDK中的当前版本为1.1.2)

将应用程序部署到主机时,出现以下错误:

HTTP错误502.5-进程失败

我相信这是因为它正在寻找运行时1.0.4。

因此,简而言之,如何定位运行时版本1.0.3?

visual-studio .net-core visual-studio-2017

3
推荐指数
1
解决办法
4511
查看次数

如何在 .NET Standard 1.5 上确定操作系统是 32 位还是 64 位跨平台?

我一直在寻找解决方案,但尽管在答案不再适用于 .NET Standard 1.5 及其跨平台思维方式之前已经提出了这个问题。此外,这个问题是关于操作系统架构而不是.NET 平台架构

我试过的

最佳答案是Environment.Is64BitOperatingSystem是一个未在 .NET Standard 1.5 中实现的 API。

答案

/// <summary>Is64s the bit operating system.</summary>
/// <returns></returns>
if (IntPtr.Size == 8)
    // 64Bit
else
    // 32bit
Run Code Online (Sandbox Code Playgroud)

不是我需要的。尽管在 .NET Standard 中仍然可以做到,但它决定了 .NET 平台的位数,而不是底层操作系统。

几乎所有其他回复都在使用[DllImport("kernel32.dll")],我几乎可以肯定除了 Windows 之外的任何东西都不会工作。

那么,我如何确定.NET Standard 1.5 支持的所有平台(Linux、iOS、Windows、Android 等)的底层操作系统的位数?

c# operating-system 32bit-64bit .net-standard .net-standard-1.5

3
推荐指数
1
解决办法
706
查看次数

c#Activator.CreateInstance不初始化变量

拥有Remember.cs:

namespace Tasks
{
    public class Remember : Task
    {
        new public string name = typeof(Remember).Name;
        new public Task.Priority priority = Task.Priority.High;
    }
}
Run Code Online (Sandbox Code Playgroud)

Task.cs:

public abstract class Task
{
    public string name;
    public Task.Priority priority = Task.Priority.Low;

    public enum Priority
    {
        High = 3,
        Medium = 2,
        Low = 1,
    }
}
Run Code Online (Sandbox Code Playgroud)

当我使用以下方法创建此类的实例时:

Task task = (Task)Activator.CreateInstance(typeof(Remember));
Debug.Log(task.name + " - " + task.priority);
Run Code Online (Sandbox Code Playgroud)

任务的名称为空,优先级是Task.Priority枚举中可用的最小数字而不是选定的数字(高).

为什么不Activator.CreateInstance初始化那些变量呢?

.net c# createinstance

3
推荐指数
1
解决办法
122
查看次数

如何从PictureBox中获取真实图像像素点x,y

我有一个pictureBox2并且它设置为zoom,我试图找出如何通过Mouse.Clickon获取图像上的真实 x,y 像素位置pictureBox2。但我尝试了我所知道的 3 种可能的想法: without/with PointToClientPointToScreen但我永远无法做到正确。

private void pictureBox2_Click(object sender, EventArgs e)
{
     MouseEventArgs me = (MouseEventArgs)e;
    txtpictureHeight.Text =( 
        (OriginalImage.GetImageHeight()*me.Location.Y)/ pictureBox2.Image.Height).ToString();
    txtpictureWidth.Text = ( 
        (OriginalImage.GetImageWidth()* me.Location.X)/ pictureBox2.Image.Width).ToString();
}
Run Code Online (Sandbox Code Playgroud)

一定有一些我需要注意的因素,所以我想使用上面的双重结果,然后我关闭了,但我的测试图像 (1371x2221) 的高度仍然有 80px。当我使用时Zoom,我的上有 2 个额外的空间pictureBox2

c# winforms

3
推荐指数
1
解决办法
4033
查看次数

忽略 ASP.NET MVC Core 路由中的第一段

我正在寻找能够匹配以下路线的路线定义:

  • /segment/xxxx/def
  • /segment/.../xxxx/def
  • /segment/that/can/span/xxxx/def

并能够xxxx使用参数 `def 运行操作。

但这种路线是不允许的:

[Route("/{*segment}/xxx/{myparam}")]
Run Code Online (Sandbox Code Playgroud)

如何做呢?

asp.net-mvc routes url-routing asp.net-mvc-routing .net-core

3
推荐指数
1
解决办法
1650
查看次数

MVCSiteMapProvider - 显示父节点的标题

我希望能够显示当前节点的父标题.

网站地图:

    <mvcSiteMapNode title="Main Site Tile" controller="Home" action="Index">
  <mvcSiteMapNode title="Some site section" controller="Section" action="Index">
    <mvcSiteMapNode title="Some page" controller="Section" action="Page1" />
    <mvcSiteMapNode title="Some other page" controller="Section" action="Page2" />
  </mvcSiteMapNode>
</mvcSiteMapNode>
Run Code Online (Sandbox Code Playgroud)

因此,在'Page1'上我可以使用以下方式显示标题(某些页面):

Html.MvcSiteMap().SiteMapTitle()
Run Code Online (Sandbox Code Playgroud)

大.但是,我还想在我的_Layout页面中显示父节点(某些网站部分)的标题,所以如果我查看'Page1'或'Page2'(或者实际上嵌套在其中的任何视图),这将显得相同.

这可能吗?

asp.net-mvc asp.net-mvc-4 mvcsitemapprovider

2
推荐指数
1
解决办法
2396
查看次数

仅使用'x'前缀导致的神秘404路由错误?

我想保持我的网址尽可能短,所以我正在测试没有分隔符的路由,如下所示:

routes.MapRoute(
   name: "Photo",
   url: "x{id}",
   defaults: new { controller = "Content", action = "Photo" }
);
Run Code Online (Sandbox Code Playgroud)

由于某种原因,上面的路线不起作用,我收到404错误:

无法找到该资源.

说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用.

但是,当我为不同的字母更改x前缀时,例如g,它工作正常.

没有冲突的路线.我在这里想念的是什么?

编辑:

我再次看到这个问题,我观察到404可能只发生在id包含x,即路线喜欢/xa1B2/xZ9y8完美无缺,但x12xG失败了.请问有什么想法吗?

c# asp.net-mvc url-routing asp.net-mvc-routing asp.net-mvc-5

2
推荐指数
1
解决办法
307
查看次数

ASP.NET MVC 5 + Owin + SimpleInjector

如果我从项目中删除DI lib,使用owin,webapi,mvc和DI(SimpleInjector)的新asp.net mvc项目运行正常.然而,一旦推出,在注册DI的OWIN组件时应用程序就会爆炸.OWIN启动配置正在被命中并且运行没有错误,但是当需要注册依赖项时(如下所示),我收到以下错误:

Microsoft.Owin.Host.SystemWeb.dll中出现"System.InvalidOperationException"类型的异常,但未在用户代码中处理

附加信息:在上下文中找不到owin.Environment项.

SimpleInjector注册码:

container.RegisterPerWebRequest<IUserStore<ApplicationUser>>(() => new UserStore<ApplicationUser>());
container.RegisterPerWebRequest<HttpContextBase>(() => new HttpContextWrapper(HttpContext.Current));
// app fails on call to line below...
container.RegisterPerWebRequest(() => container.GetInstance<HttpContextBase>().GetOwinContext());
container.RegisterPerWebRequest(() => container.GetInstance<IOwinContext>().Authentication);
container.RegisterPerWebRequest<DbContext, ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)

更新 - 完整堆栈跟踪

在WebApplication1.App_Start.SimpleInjectorInitializer的System.Web.HttpContextBaseExtensions.GetOwinContext(HttpContextBase context)中.<> c__DisplayClass6.b__2()在b:\ temp\WebApplication1\WebApplication1\App_Start\SimpleInjectorInitializer.cs:第41行在lambda_method(Closure)at SimpleInjector.Scope.CreateAndCacheInstance [TService,TImplementation](ScopedRegistration 2 registration) at SimpleInjector.Scope.GetInstance[TService,TImplementation](ScopedRegistration2 registration),位于SimpleInjector.Scope.GetInstance [TService,TImplementation](ScopedRegistration 2 registration, Scope scope) at SimpleInjector.Advanced.Internal.LazyScopedRegistration2.GetInstance(范围范围),位于SimpleInjector.InstanceProducer.GetInstance()的lambda_method(Closure)

c# asp.net-mvc dependency-injection simple-injector owin

2
推荐指数
1
解决办法
4173
查看次数

MVC5 Ninject绑定和HttpContext

我正在尝试建立一个新项目,并且我添加了一个新类MembershipService,它需要在它的构造函数中传递HttpContext.

在之前的项目中,我使用了代码

    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<IMembershipService>()
            .To<MembershipService>()
            .InRequestScope()
            .WithConstructorArgument("context", HttpContext.Current);
       ....
    }
Run Code Online (Sandbox Code Playgroud)

然而,在新项目中,我正在使用Ninject Modules,在对StackOverflow和Google进行一些搜索之后,我提出了以下代码:public class ServiceHandlerModule:NinjectModule {

    public override void Load()
    {

        Bind<IMembershipService>()
            .To<MembershipService>()
            .WithConstructorArgument("context", ninjectContext=> HttpContext.Current);


        this.Kernel.Bind(x =>
        {
            x.FromAssemblyContaining(typeof(NinjectWebCommon))
                .SelectAllClasses()
                .Where(t => t != typeof(MembershipService))
                .BindDefaultInterface();
        });
        this.Kernel.Bind(x =>
        {
            x.FromAssemblyContaining<BrandServiceHandler>()
                .SelectAllClasses()
                .Where(t => t != typeof(MembershipService))
                .BindDefaultInterface();
        });

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误:

描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

异常详细信息:Ninject.ActivationException:激活字符串时出错没有匹配的绑定可用,并且该类型不可自我绑定.激活路径:

5)将依赖字符串注入到HttpRequest类型的构造函数的参数filename中

4)将依赖关系HttpRequest注入到HttpContext类型的构造函数的参数请求中

3)将依赖关系HttpContext注入到MembershipService类型的构造函数的参数httpContext中

2)将依赖关系IMembershipService注入到HomeController类型的构造函数的参数membershipService中

1)请求HomeController

谁能指出我哪里出错了?

谢谢,约翰

c# asp.net-mvc dependency-injection ninject httpcontext

2
推荐指数
2
解决办法
5270
查看次数

依赖注入类型选择

最近,我遇到了一个必须基于参数选择类型的问题。例如:用于发送通知的类,该类应根据输入参数选择正确的通道(电子邮件,短信,...)。

我看起来像这样:

public class NotificationManager 
{
    IEmail _email;
    ISms _sms;

    public NotificationManager (IEmail email, ISMS sms) 
    {
        _email = email;
        _sms = sms;
    }

    public void Send(string type) 
    {
        switch(type) 
        {
            case "email":
                _email.send;
                break;

            case "sms":
                _sms.send;
                break;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里的问题是,当我使用这种构造时,构造函数在发送通知的所有不同方法中迅速增长。

我真的不喜欢这样,这使得对选择单元进行单元测试变得难以操作。

我不能简单地说,new email();因为通知类型的电子邮件将依赖IEmailManager,这只会解决问题。

是否有某种模式可以执行相同的操作,但是方式更好,更清洁?

c# architecture dependency-injection

2
推荐指数
1
解决办法
373
查看次数