[英]Xaml Designer crashes
我在我的项目中使用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));
}
}
理想的是为设计人员提供一个ViewModel
,为运行时提供一个ViewModel
。 这取决于将MainTabViewModel
到View
。 在您的View
使用以下代码段确定它在设计器中的执行时间:
bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this)
this
是您的View
。
您应该使用结果跳过任何与数据库相关的执行。
您正在尝试访问在设计器中不起作用的数据库。 您需要重构代码,以便可以在必要时使用设计时数据,并且仅在运行时使用数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.