2012-07-18 25 views
2

我尝试运行http://mvcmusicstore.codeplex.com/releases/view/64379中列出的MVC Music Store应用时出现异常。只要我在Models文件夹中包含SampleData.cs并对其进行一些更改以包含此模型,我就会得到一个ArgumentException,路径中存在非法字符。任何类似的经历?有人可以帮助解决这个问题,因为我暂时停滞了一段时间。在模型中包含SampleData.cs后尝试运行MVC Music Store时发生异常

感谢

任何输入请

精确的代码如下,

public class MusicStoreEntities : DbContext 
{ 
    public DbSet<Album> Albums { get; set; } 
    public DbSet<Genre> Genres { get; set; } 
} 

我添加SampleDat.cs文件到我的模型。这是一个巨大的文件,我只列出它的一部分。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.Entity; 

namespace MvcMusicStore.Models 
{ 
    public class SampleData : DropCreateDatabaseIfModelChanges<MusicStoreEntities> 
    { 
     protected override void Seed(MusicStoreEntities context) 
     { 
      var genres = new List<Genre> 
      { 
       new Genre { Name = "Rock" }, 
       new Genre { Name = "Jazz" } 
      }; 

      var artists = new List<Artist> 
      { 
       new Artist { Name = "Aaron Copland & London Symphony Orchestra" }, 
       new Artist { Name = "Aaron Goldberg" } 
      }; 

      new List<Album> 
      { 
       new Album { Title = "The Best Of Men At Work", 
          Genre = genres.Single(g => g.Name == "Rock"), 
          Price = 8.99M, 
          Artist = artists.Single(a => a.Name == "Men At Work"), 
          AlbumArtUrl = "/Content/Images/placeholder.gif" 
          }, 
       new Album { Title = "A Copland Celebration, Vol. I", 
          Genre = genres.Single(g => g.Name == "Classical"), 
          Price = 8.99M, 
          Artist = artists.Single(a => a.Name == "Aaron Copland & London Symphony Orchestra"), 
          AlbumArtUrl = "/Content/Images/placeholder.gif" 
          } 
      }.ForEach(a => context.Albums.Add(a)); 
     } 
    } 
} 

我在Global.asax设定数据初始化程序,

protected void Application_Start() 
{ 
    System.Data.Entity.Database.SetInitializer(new MvcMusicStore.Models.SampleData()); 
} 

在我的控制器,StoreController.cs我做

var genres = storeDB.Genres.ToList(); 

,并得到follwing例外。

Exception is "Illegal characters in path."

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Illegal characters in path.

Source Error:

public ActionResult Index() 
{ 
    var genres = storeDB.Genres.ToList(); 
    return View(genres); 
} 

Stack Trace:

[ArgumentException: Illegal characters in path.] 
System.IO.Path.CheckInvalidPathChars(String path) +126 
System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) +145 
System.IO.Path.GetFullPathInternal(String path) +46 
System.IO.Path.GetFullPath(String path) +33 
System.Data.SqlServerCe.SqlCeUtil.DemandForPermission(String filename, FileIOPermissionAccess permissions) +71 
System.Data.SqlServerCe.SqlCeEngine.CreateDatabase() +1217 
System.Data.SqlServerCe.SqlCeProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 timeOut, StoreItemCollection storeItemCollection) +288 
System.Data.Objects.ObjectContext.CreateDatabase() +84 
System.Data.Entity.Internal.DatabaseOperations.Create(ObjectContext objectContext) +35 
System.Data.Entity.Database.Create() +70 
System.Data.Entity.DropCreateDatabaseIfModelChanges`1.InitializeDatabase(TContext context) +477 
System.Data.Entity.<>c__DisplayClass2`1.<SetInitializerInternal>b__0(DbContext c) +143 
System.Data.Entity.Internal.<>c__DisplayClass5.<PerformDatabaseInitialization>b__3() +59 
System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +101 
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +260 
System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +31 
System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +147 
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +276 
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +112 
System.Data.Entity.Internal.InternalContext.Initialize() +41 
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +34 
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +148 
System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +33 
System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator() +91 
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +315 
System.Linq.Enumerable.ToList(IEnumerable`1 source) +58 
MvcMusicStore.Controllers.StoreController.Index() in C:\My Projects\MvcMusicStore\MvcMusicStore\Controllers\StoreController.cs:16 
lambda_method(Closure , ControllerBase , Object[]) +96 
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17 
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263 
System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19 
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191 
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343 
System.Web.Mvc.Controller.ExecuteCore() +116 
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97 
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37 
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21 
System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12 
System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62 
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50 
System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22 
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60 
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061 
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184 
+0

任何帮助来解决此异常??? – user1528884

+0

@ user152884你得到了什么异常,并且将相关代码发布到你正在做的事情上。 – tkt986

+0

添加代码,异常详细信息和堆栈跟踪 – user1528884

回答

1

当我阅读本教程时,由于我添加到我的Web.Config文件中的错误,导致出现此错误。确保您的<connectionString>节点看起来完全是这样的:

<connectionStrings> 
    <add name="MusicStoreEntities" 
     connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf" 
     providerName="System.Data.SqlServerCe.4.0" /> 
    </connectionStrings> 
+0

这对我有效。我在连接字符串中输入了“Data Directory”而不是“DataDirectory”。当我纠正我能够前进时。 – Animesh

2

的soulution是对这个职位 [http://mvcmusicstore.codeplex.com/discussions/359070][1]

肯定的是, MusicStoreEntities实现DbContext为:

namespace MvcMusicStore.Models 
{ 
    public class MusicStoreEntities : DbContext 
    { 
     public DbSet<Album> Albums { get; set; } 
     public DbSet<Genre> Genres { get; set; } 
    } 
} 
相关问题