Spirosi
Spirosi

Reputation: 324

Xaml Designer crashes

I'm using VS 2012 in my project, and i've got such XAML designer crush.

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));

                }

            }

Upvotes: 2

Views: 178

Answers (2)

Ed Chapel
Ed Chapel

Reputation: 6952

It is ideal to have a ViewModel for the designer and another for runtime. This depends on how you are wiring your MainTabViewModel to your View. Use the following snippet in your View to determine when it is executing in a designer:

bool isInDesignMode = DesignerProperties.GetIsInDesignMode(this)

where this is your View.

You should use the result to skip any database-related execution.

Upvotes: 2

t3chb0t
t3chb0t

Reputation: 18744

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.

Upvotes: 1

Related Questions