小编Tro*_*acy的帖子

无法解析目标框架“.NETFramework,版本=v4.6.1”的 mscorlib

当我尝试在 .NET 4.6.1 项目中更新或配置服务引用时,VS 抛出下一个错误:

无法解析目标框架“.NETFramework,版本=v4.6.1”的 mscorlib。如果未安装目标框架或框架名称格式不正确,则可能会发生这种情况。

路径长度没问题,我还检查了其他答案,但没有任何作用。也许有人有类似的事情?

c# mscorlib service-reference visual-studio visual-studio-2017

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

我可以将C#7.3与.Net Framework 4.6.1一起使用吗?

我对enum通用约束感兴趣,但是当我在Build上切换项目的语言版本时高级,我仍然遇到错误« C#5中不可用;即使重新打开项目,也请使用语言版本7.3或更高版本 »。
项目类型是ASP.NET MVC应用程序。

.net c# asp.net-mvc generic-constraints c#-7.3

6
推荐指数
1
解决办法
2243
查看次数

MVC5中的WWWROOT

如何在ASP.NET MVC5中使用静态文件实现相同的行为,例如它在aspnet-core上的正常工作app.UseDefaultFiles(); app.UseStaticFiles();

我的意思是从根目录下的某个文件夹提供静态文件,例如/wwwroot/some.html必须在mysite.com/some.html,等等上/wwwroot/img/test.jpg打开mysite.com/img/test.jpg

更新:我已经创建了wwwroot文件夹,并将以下规则添加到web.config

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Rewrite Static" stopProcessing="true">
          <match url="^(?!(wwwroot/|api/))(.*)$" ignoreCase="true"></match>
          <action type="Rewrite" url="/wwwroot/{R:1}" />
        </rule>
      </rules>
Run Code Online (Sandbox Code Playgroud)

所以,IIS必须返回文件wwwroot除了当来电去/api/something,但我一直都想与index.htmlwwwroot文件夹中,从来没有其他文件。Api的网址效果很好。
我做错了什么?

iis asp.net-mvc url-rewriting static-files asp.net-mvc-5

6
推荐指数
1
解决办法
174
查看次数

ASP.NET Core JSON-RPC

我创建了核心的WebAPI项目,尽管RESTing表现不错,但还需要JSON-RPC功能。我看到的东西像这样这样,但仍然不知道它们中的哪一个优先组织的服务器和客户端(这是aspnetcore太)好更换的像WCF。

那么,如何以正确的方式使用ASP.NET Core进行JSON-RPC?

c# json-rpc asp.net-core asp.net-core-webapi

5
推荐指数
1
解决办法
491
查看次数

MVC5 Web API 和依赖注入

尝试在没有第三方工具的情况下在 Web API 2 上做一些 DI。
因此,从一些示例中我得到了自定义依赖项解析器(为什么没有集成的?奇怪,甚至Microsoft.Extensions.DependencyInjection都没有提供):

public class DependencyResolver : IDependencyResolver
    {
        protected IServiceProvider _serviceProvider;

        public DependencyResolver(IServiceProvider serviceProvider)
        {
            this._serviceProvider = serviceProvider;
        }

        public IDependencyScope BeginScope()
        {
            return this;
        }

        public void Dispose()
        {

        }

        public object GetService(Type serviceType)
        {
            return this._serviceProvider.GetService(serviceType);
        }

        public IEnumerable<object> GetServices(Type serviceType)
        {
            return this._serviceProvider.GetServices(serviceType);
        }

        public void AddService()
        {

        }
    }
Run Code Online (Sandbox Code Playgroud)

然后创建了这个类:

public class ServiceConfig
    {
        public static void Register(HttpConfiguration config)
        {
            var services = new ServiceCollection();
            services.AddScoped<IMyService, MyServiceClient>();

            var resolver …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection asp.net-web-api asp.net-mvc-5 asp.net-web-api2

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

VS diff 工具的自上而下模式

当我并排打开两个文件时,打开一些差异会迫使我在工作区域的 1/4 宽度中观看文件,这很不舒服。有什么办法可以改变这种行为吗?

diff visual-studio visual-studio-2017

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

传递 ValueTuple 而不是参数

是否可以这样做(或者我可能需要特定版本的 C#)?

Function<int,int,int,int> triSum = (a,b,c) => {return a+b+c;};
var tup = (1,2,3);
triSum(tup); //passing one tuple instead of multiple args
Run Code Online (Sandbox Code Playgroud)

更新:我的意思是传递元组而不是单独的参数。

public void DoWrite(string s1, string s2)
{
Console.WriteLine(s1+s2);
}
public (string,string) GetTuple()
{
//return some of them
}
//few lines later
DoWrite(GetTuple());
Run Code Online (Sandbox Code Playgroud)

c# tuples parameter-passing valuetuple

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

dotnet.exe 与 w3wp.exe:有什么区别?

我看到应用程序托管为dotnet.exe而我的应用程序简单

       WebHost
              .CreateDefaultBuilder(args)
              .UseConfiguration(config)
            //.UseContentRoot(Directory.GetCurrentDirectory())

            .UseEnvironment(environment)

            //.UseIIS() //even commented those; still no effort
            //.UseIISIntegration()
            .UseStartup<Startup>()
Run Code Online (Sandbox Code Playgroud)

运行为w3wp.exe.
有什么区别以及如何切换?我之所以这么问,是因为dotnet.exe托管应用程序在处理大量数据(> 5GB)时运行良好,而我的应用程序w3wp.exe在 2.6GB 上运行失败AccessViolation

更新:我的应用程序在非托管池上运行,而基于 dotnet.exe 的应用程序使用.NET 4.

c# iis access-violation .net-core asp.net-core

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

DI 和基类

我通过典型示例创建了简单的asp.net core应用程序,它按预期工作。然后我通过appsettings.json添加了配置支持,如下所示:

[ApiController]
[Route("[controller]/[action]")]
public class MyController: BaseController
{
private IConfiguration _configuration = null;
public MyController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
//some actions here
}
Run Code Online (Sandbox Code Playgroud)

它也起作用了。Configuration但现在我想在我的基类( )中实现BaseController,以便所有派生控制器都可以访问它。
没什么难的,我想并改写为:
公开课

[ApiController]
[Route("[controller]/[action]")]
public class MyController: BaseController
{
//some actions here
}

public class BaseController: ControllerBase
{
        private IConfiguration _configuration = null;
        public IConfiguration Configuration
        {
            get
            {
                return _configuration;
            }
        }

        public BaseController(IConfiguration configuration = null)
        {
            _configuration = configuration;
        }
} …
Run Code Online (Sandbox Code Playgroud)

c# inheritance dependency-injection asp.net-core

0
推荐指数
1
解决办法
2677
查看次数