2014-12-09 3 views
2

내 프로젝트에서 VS 2012를 사용하고 있으며 이러한 XAML 디자이너가 압도적 인 상태입니다. 여기 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

디자이너는 ViewModel이고 런타임은 다른 디자이너에게 적합합니다. 이는 MainTabViewModelView에 연결하는 방법에 따라 다릅니다. 이 디자이너에서 실행되는시기를 결정하기 위해 View에 다음 코드를 사용하여

bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this) 

thisView입니다.

결과를 사용하여 데이터베이스 관련 실행을 건너 뜁니다.

1

문제를 생성하는 코드입니다. 필요한 경우 디자인 타임 데이터를 사용하고 런타임에만 데이터베이스를 사용할 수 있도록 코드를 리팩토링해야합니다.