Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
428 views
in Technique[技术] by (71.8m points)

c# - Problems with RavenDB.Client reference in asp.net 5.0 project.json

I'm trying to build a RavenApiController with the new ASP.NET 5.0 (aka Asp.Net vNext) stuff and can't seem to get the RavenDB.Client references to work at all.

The error I get is

Error CS0246 The type or namespace name 'Raven' could not be found (are you missing a using directive or an assembly reference?) SharedIO.ASP.NET Core 5.0 RavenApiController.cs 3

My project.json is as follows

{
"webroot": "wwwroot",
"version": "1.0.0-*",
"exclude": [
    "wwwroot"
],
"packExclude": [
    "**.kproj",
    "**.user",
    "**.vspscc"
],
"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta2",
    "RavenDB.Client": "3.0.3599",
    "SharedIOModel": "1.0.0-*"
},
"frameworks": {
    "aspnet50": {},
    "aspnetcore50": {}
}

}

The code for RavenApiController.cs which fails to build on the third line begins as:

    using System;
    using Microsoft.AspNet.Mvc;
    using Raven.Client;
    using Raven.Client.Document;;

    namespace SharedIO.Controllers
    {
        [RequireHttps]
        public abstract class RavenAPIController : Controller
        {
            public IDocumentStore Store
            {
                get { return LazyDocStore.Value; }
            }

Totally stumped.

For what it's worth intellisense seems to be able to find the reference just fine and I don't get an error until I actually 'build solution.

Also Intellisense shows me that (for example) Raven.Client.Document.IDocumentStore is 'Available' in ASP.NET 5.0 but 'Not Available' in 'ASP.NET Core 5.0'.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem is that you referencing RavenDB.Client in the top level dependencies node in project.json. That means that those dependencies are applicable to both Desktop CLR (aspnet50) and CoreCLR (aspnetcore50).

When you build an ASPNET 5 project, all configurations are built, not just the "active" one. Mostly sure RavenDB.Client works only with the Desktop CLR so move it under a dependencies node under that configuration.

"dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta2",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta2",
    "Microsoft.AspNet.Mvc": "6.0.0-beta2",
    "SharedIOModel": "1.0.0-*"
},
"frameworks": {
    "aspnet50": {
        "dependencies" : {
            "RavenDB.Client": "3.0.3599",
        }
    },
    "aspnetcore50": {}
}

Then you might have to either use some conditional blocks in your code (#if ASPNET50) or remove CoreCLR all together.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...