简体   繁体   English

Xaml Designer崩溃

[英]Xaml Designer crashes

I'm using VS 2012 in my project, and i've got such XAML designer crush. 我在我的项目中使用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()

And here is the code that creates the issue 这是造成问题的代码

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

                }

            }

It is ideal to have a ViewModel for the designer and another for runtime. 理想的是为设计人员提供一个ViewModel ,为运行时提供一个ViewModel This depends on how you are wiring your MainTabViewModel to your View . 这取决于将MainTabViewModelView Use the following snippet in your View to determine when it is executing in a designer: 在您的View使用以下代码段确定它在设计器中的执行时间:

bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this)

where this is your View . this是您的View

You should use the result to skip any database-related execution. 您应该使用结果跳过任何与数据库相关的执行。

You are trying to access a database which does not work in the designer. 您正在尝试访问在设计器中不起作用的数据库。 You need to refactor your code so that you can use design time data if necessary and the database only at runtime. 您需要重构代码,以便可以在必要时使用设计时数据,并且仅在运行时使用数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM