Xaml Designer崩溃了

时间:2014-12-09 06:27:13

标签: c# wpf visual-studio-2012

我在我的项目中使用VS 2012,并且我有这样的XAML设计师粉碎。

Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteException

No connection string named '************' could be found in the application config file.
   at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
   at *************.ViewModel.**********.<GetReferralList>b__1d() in d:\******.cs:line 422
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ***************.<GetReferralList>d__29.MoveNext() in *******************\MainTabViewModel.cs:line 391
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state)
   at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

以下是创建问题的代码

await Task.Run(() =>
        {
            using (var context = new SCMEntities())
            {
                var listOfGenRefReg = context.GenericReferralRegistrationIs;
                foreach (var item in listOfGenRefReg)
                {
                         Application.Current.Dispatcher.Invoke(() =>
                            LastReferrals.Add(item));

                }

            }

2 个答案:

答案 0 :(得分:2)

最好是为设计师设置ViewModel,为运行时提供另一个设置。这取决于您将MainTabViewModel连接到View的方式。在View中使用以下代码段来确定它在设计器中的执行时间:

bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this)

其中this是您的View

您应该使用结果跳过任何与数据库相关的执行。

答案 1 :(得分:1)

您正在尝试访问在设计器中不起作用的数据库。您需要重构代码,以便在必要时可以使用设计时数据,仅在运行时使用数据库。