小编Sam*_*Sam的帖子

找不到.deps.json

按照以下菜单顺序:

文件 - >新建 - >项目 - > ASP> .NET核心Web应用程序(.Net Framework)

构建 - >构建解决方案

得到此错误:

错误C:\ Users\Sam\Documents\Visual Studio 2015\Projects\RC2 Test\src\RC2 Test\error CS2001:源文件'C:\ Users\Sam\Documents\Visual Studio 2015\Projects\RC2 Test\src \找不到RC2 Test\Test.deps.json'.RC2测试C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 241

搜索test.deps什么也找不到.

"test"是单元测试项目的硬编码名称吗?
dotnet --version说1.0.0.0-preview1-002702

编辑:

我重复了上述步骤,但这次我选择了Core Web Application(.Net Core).我犯了同样的错误.

看起来我们不能在项目名称中使用空格.

.net

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

TAP全局异常处理程序

此代码抛出异常.是否可以定义将捕获它的应用程序全局处理程序?

string x = await DoSomethingAsync();
Run Code Online (Sandbox Code Playgroud)

使用.net 4.5/WPF

.net c# exception task-parallel-library async-await

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

将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<MvcOptions>(options =>
        {
            options.OutputFormatters.RemoveType<JsonOutputFormatter>();
            options.OutputFormatters.Insert(0, formatter);
        });

        //etc...
    }    
Run Code Online (Sandbox Code Playgroud)

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

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

附加类型的实体失败,因为相同类型的另一个实体已具有相同的主键值

错误消息:附加类型的实体失败,因为同一类型的另一个实体已具有相同的主键值.

问题:如何以类似的方式附加实体,如下面的代码中的AttachActivity方法所示?

我必须假设上面的错误消息的"另一个实体"部分是指存在于内存但超出范围(??)的对象.我注意到这一点,因为我尝试附加的实体类型的DBSet的Local属性返回零.

我有理由相信实体在上下文中不存在,因为我逐步完成代码并在创建时观察上下文.在创建dbcontext之后,实体将立即添加到几行中.

我正在测试这里指定的附加实体:找出实体是否附加到dbContext的最合理方法是什么?

当在visual studio的locals窗口中查看本地时,我看到没有类型为Activity的实体(无论ID),除了我想要附加的实体.

代码按以下顺序执行:Try - > ModifyProject - > AttachActivity

代码在注释行的AttachActivity中失败.

请注意调试注释之间的代码,如果已将任何实体添加到上下文中,则将抛出该代码.

private string AttachActivity(Activity activity)
    {
        string errorMsg = ValidateActivity(activity);  // has no code yet.  No. It does not query db.

        if(String.IsNullOrEmpty(errorMsg))
        {
            // debug 
            var state = db.Entry(activity).State; // Detached
            int activityCount = db.Activities.Local.Count;
            int projectCount = db.Activities.Local.Count;

            if (activityCount > 0 || projectCount > 0)
                throw new Exception("objects exist in dbcontext");
            // end debug
            if (activity.ID == 0)
                db.Activities.Add(activity);
            else
            {
                db.Activities.Attach(activity); …
Run Code Online (Sandbox Code Playgroud)

.net c# entity-framework

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

在iis 8.5中为mvc和webapi应用程序进行路由

我正在运行Windows 8 IIS 8.5.

我在IIS上创建了我的网站,并在下面的目录中为我的webapi服务创建了另一个网站所以我的网站看起来像这样:

www.mysite.com

www.mysite.com/api //这在磁盘上存在于站点dir下面名为api的目录中.在IIS中配置为站点而非虚拟目录.

当然,iis无法为这两个站点实现路由.

如果我添加/index.html,ww.mysite.com有效.如果我在浏览器中输入www.mysite.com,我会收到404.

无论我做什么,api网站都会给我404错误.

在visual studio中运行时,这两个站点都可以正常工作 www.mysite.com是一个mvc 5应用程序www.mysite.com/api是一个webapi 3应用程序.

一些问题,如这一个:
ASP.NET 4.5 MVC 4不适用于Windows Server 2008 IIS 7 推荐

<modules runAllManagedModulesForAllRequests="true" /> 
Run Code Online (Sandbox Code Playgroud)

哪个不起作用,即使它确实有效也不是最理想的.

其他人发现的其他问题:

正在部署Global.asax.

.net 4.5安装在控制面板下 - >添加Windows功能 - > IIS - >应用程序开发

未安装WebDav

aspnet_regiis -i不相关(使用控制面板)

启用默认错误处理

这是web.configs:

web.config from mysite

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings> …
Run Code Online (Sandbox Code Playgroud)

asp.net iis asp.net-mvc routing asp.net-web-api

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

如何在加载/卸载时在页面上实现淡入/淡出效果?

我想我已经连接了基本的动画部分,我只需要知道要处理的事件.理想情况下,我想要一个我可以在导航级别使用的解决方案,所以我可以包装我的所有组件,但一个简单的页面加载示例就足够了,非常感激.我在SO上发现了其他一些相关问题,但它们似乎没有回答我的具体问题或过时:

使用Angular 2.0路由器和组件接口承诺的路由组件页面过渡动画的Angular 2"动画幻灯片"

这是我到目前为止:

html文件

<article @heroState="componentState">
           <p>article element should fade in/out</p>
</article>
Run Code Online (Sandbox Code Playgroud)

零件

@Component({
    selector: 'blog-about',
    templateUrl: './app/about/about.html',
    animations: [
        trigger('heroState', [
            state('active', style({
                backgroundColor: 'blue',
                transform: 'scale(1)'
            })),
            state('inactive', style({
                backgroundColor: 'green',
                transform: 'scale(1.1)'
            })),
            transition('active => inactive', animate('1000ms ease-in')),
            transition('inactive => active', animate('1000ms ease-out'))
        ])
    ]
})
export class About implements OnInit, OnDestroy {
    public componentState: string;
    public Title: string

    constructor() {
        this.Title = "this is about";
    }

    ngOnInit()
    {
        this.componentState = 'inactive'; …
Run Code Online (Sandbox Code Playgroud)

angular2-router3 angular

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

如何将Async方法作为Action或Func传递

我有一个小实用工具方法,用于在using语句中实例化我的datacontext.我想在异步方法调用中使用它,但是在方法返回之前处理datacontext.使用它的正确方法是什么?

这是方法(和重载)

    public void Try(Action<IDataServices> method)
    {
        using (IDataServices client = GetClient())
        {
            method(client);
        }
    }

    public TResult Try<TResult>(Func<IDataServices, TResult> method)
    {
        using (IDataServices client = GetClient())
        {
            return (TResult)method(client);
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是我当前使用它的方式(失败):

    Model m = await ClientResolver.Try(async x => await x.GetModelByIDAsync(modelID));
Run Code Online (Sandbox Code Playgroud)

参考:
在using语句中调用异步方法

c# async-await

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

如何从logevent获取格式化的输出

在WriteTo.Observer方法中,我想传递格式化日志消息,因为它是使用格式化模板呈现的。我该怎么做?谢谢

class Program
{
    static void Main(string[] args)
    {
        Log.Logger = new LoggerConfiguration()
            .MinimumLevel.Information()
            .WriteTo.LiterateConsole()
            .WriteTo.RollingFile("log-{Date}.txt")
            .WriteTo.Observers(events => events.Do(evt => { Console.WriteLine($"Observed event {evt.MessageTemplate.Text}"); }).Subscribe())
            .WriteTo.Observers(events => events.Do(evt => { LogHandler(evt.MessageTemplate.Text);}).Subscribe())
            .CreateLogger();

        Log.Logger.Information("Log msg from Main");
        Console.ReadLine();
    }

    public static void LogHandler(string logMsg)
    {
        Console.WriteLine("LogHandler: " + logMsg); //I want the complete formatted log message as it would appear in a file i.e. "[10:20:14 INF] Log msg from DoNothing"
    }
}
Run Code Online (Sandbox Code Playgroud)

serilog

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