Entity Framework connection string error in Azure - entity-framework

I am currently running into a error upon deploying to Azure.
I took the connection string directly from my web config file, which works when testing locally, and i modified it to fit my deployment to Azure, but then i get an error.
Below is the original connection string that works on my local machine:
<add name="DataEntities" connectionString="metadata=res://*/Models.FirearmModels.csdl|res://*/Models.FirearmModels.ssdl|res://*/Models.FirearmModels.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\Data.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Below is the modified connection string for Azure:
<add name="DataEntities" connectionString="metadata=res://*/Models.FirearmModels.csdl|res://*/Models.FirearmModels.ssdl|res://*/Models.FirearmModels.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:owm5115h08.database.windows.net,1433;Initial Catalog=diafirearmserver;User ID=userid;Password=userpass;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Could someone please tell me what i am doing wrong, what i am missing, in getting this to work?
Thanks in advance.
PS: Here's a screenshot of the error i get when i run it in Azure:
http://i693.photobucket.com/albums/vv293/saturobi360/EntityConnString_Error_zpsyrt1f9jg.jpg
My apologies on the quality of the image.
My apologies:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
An error occurred while executing the command definition. See the inner exception for details.
</ExceptionMessage>
<ExceptionType>
System.Data.Entity.Core.EntityCommandExecutionException
</ExceptionType>
<StackTrace>
at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.<ExecuteStoreCommandsAsync>d__c.MoveNext() --- 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.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.<ExecuteAsync>d__0`1.MoveNext() --- 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.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__3d`1.MoveNext() --- 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.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__9`1.MoveNext() --- 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.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult() at System.Data.Entity.Core.Objects.ObjectQuery`1.<GetResultsAsync>d__e.MoveNext() --- 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.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult() at System.Data.Entity.Internal.LazyAsyncEnumerator`1.<FirstMoveNextAsync>d__0.MoveNext() --- 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.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<FirstOrDefaultAsync>d__25`1.MoveNext() --- 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 DIA_FirearmsAPIversion2.Controllers.FirearmsController.<GetFirearm>d__2.MoveNext() --- 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.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext() --- 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.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- 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.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- 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.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext() --- 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.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
</StackTrace>
<InnerException>
<Message>An error has occurred.</Message>
<ExceptionMessage>Invalid object name 'dbo.Firearms'.</ExceptionMessage>
<ExceptionType>System.Data.SqlClient.SqlException</ExceptionType>
<StackTrace>
at System.Data.SqlClient.SqlCommand.<>c__DisplayClass16.<ExecuteDbDataReaderAsync>b__17(Task`1 result) at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.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.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.<ExecuteStoreCommandsAsync>d__c.MoveNext()
</StackTrace>
</InnerException>
My original connection string for local:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-DIA_FirearmsAPIversion2-20151118042347.mdf;Initial Catalog=aspnet-DIA_FirearmsAPIversion2-20151118042347;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DataEntities" connectionString="metadata=res://*/Models.FirearmModels.csdl|res://*/Models.FirearmModels.ssdl|res://*/Models.FirearmModels.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\Data.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="DIA_FirearmsAPIversion2Context" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=DIA_FirearmsAPIversion2Context-20151118164215; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|DIA_FirearmsAPIversion2Context-20151118164215.mdf" providerName="System.Data.SqlClient" />
My connection string to Azure:
<add name="DefaultConnection" connectionString="Data Source=tcp:owm5115h08.database.windows.net,1433;Initial Catalog=diafirearmserver;User Id=username;Password=userpassword" providerName="System.Data.SqlClient" />
<add name="DataEntities" connectionString="metadata=res://*/Models.FirearmModels.csdl|res://*/Models.FirearmModels.ssdl|res://*/Models.FirearmModels.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:owm5115h08.database.windows.net,1433;Initial Catalog=diafirearmserver;User ID=username;Password=userpassword;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="DIA_FirearmsAPIversion2Context" connectionString="Data Source=tcp:owm5115h08.database.windows.net,1433;Initial Catalog=diafirearmserver;User Id=username;Password=userpassword" providerName="System.Data.SqlClient" />

This error seems to suggest that you don't have automatic migrations/database migrations have not been run on your azure version of the database.
Mainly you added a "Firearms" table but the azure table doesn't contain this table

Related

Postgres Npgsql.PostgresException deadlock detected

We are developing a group chat application and using PostgreSQL to store chat messages.
CREATE TABLE public.chatmessage
(
chatmessageid uuid NOT NULL DEFAULT uuid_generate_v4(),
text character varying COLLATE pg_catalog."default",
planid uuid NOT NULL,
userid uuid NOT NULL,
createdat timestamp with time zone NOT NULL DEFAULT timezone('utc'::text, now()),
updatedat timestamp with time zone,
deleted boolean NOT NULL DEFAULT false,
viewedallstatus boolean,
vieweduserids uuid[],
alloweduserids uuid[],
CONSTRAINT chatmessage_pkey PRIMARY KEY (chatmessageid)
)
To manage read status, we are storing the userIds of viewed participants in vieweduserIds column.
While heavily using the group chat with 5 or more participants, we are getting the following exception,
Npgsql.PostgresException (0x80004005): 40P01: deadlock detected
at Npgsql.NpgsqlConnector.<DoReadMessage>d__157.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnector.<ReadMessage>d__156.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlConnector.<ReadMessage>d__156.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlDataReader.<NextResult>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.<<NextResultAsync>b__31_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.<Execute>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlCommand.<ExecuteNonQuery>d__84.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlCommand.<>c__DisplayClass83_0.<<ExecuteNonQueryAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Dapper.SqlMapper.<ExecuteImplAsync>d__37.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 646
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
I feel since the application simultaneously updates the same column this issue is coming. The query which updates vieweduserIds column is as follows,
"Update ChatMessage Set ViewedUserIds = ViewedUserIds || #UserId Where PlanId = #PlanId And #UserId = Any(AllowedUserIds) And Not (#UserId = Any(ViewedUserIds)) And Deleted = False;"
How can we resolve this issue?
A deadlock is no problem unless it happens frequently.
The correct solution is for the application not to panic, but simply to retry the database transaction.
If deadlocks happen too frequently, you need to investigate and remedy the cause. Usually that means to keep your transactions short and small and to always lock objects in a certain order.
If you need specific help, read the PostgreSQL log file to find out which queries are involved. You'll have to understand which locks conflict to determine the root cause.

Service fabric TypeInitializationException during Application Upgrade

I am trying to upgrade the app version for one our SF solutions. But failed multiple times as one of the services is reporting an issue during start with the new version.
Here is what I see as 2 exceptions happening almost at the same time:
OnApply
Unexpected service exception. Type: System.TypeInitializationException Message: The type initializer for 'MyCompany.MyService.Interfaces.Models.MyUser' threw an exception. HResult: 0x80131534
Log record. Type: BeginTransaction LSN: 103498
at System.Fabric.Store.TStore`5.OnApplyAdd(TransactionBase txn, MetadataOperationData metadataOperationData, RedoUndoOperationData operationRedoUndo, Boolean isIdempotent, String applyType)
at System.Fabric.Store.TStore`5.<OnRecoveryApplyAsync>d__299.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Fabric.Store.TStore`5.<Microsoft-ServiceFabric-Replicator-IStateProvider2-ApplyAsync>d__237.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Replicator.DynamicStateManager.<OnApplyAsync>d__106.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Replicator.DynamicStateManager.<OnApplyAsync>d__105.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Replicator.OperationProcessor.<ApplyCallback>d__36.MoveNext().
And
Exception in OpenAsync. Type: System.TypeInitializationException Message: The type initializer for 'MyCompany.MyService.Interfaces.Models.MyUser' threw an exception. HResult: 0x80131534. Stack Trace: at Microsoft.ServiceFabric.Replicator.RecoveryManager.<PerformRecoveryAsync>d__31.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Replicator.LoggingReplicator.<PerformRecoveryAsync>d__137.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.ServiceFabric.Replicator.DynamicStateManager.<OpenAsync>d__109.MoveNext().
I would expect to see this kind of error in case any changes happened to the "MyUser" model, but it was not changed at all.
Not sure if it has to do with some kind of an issue with the SF version we are using: 5.7.198 as this is not the latest one.
Anyone faced something similar or have good ideas for a work around?
P.S. This is a production system with real customers. Being able to make upgrades and not loosing their data is a must. Hence re-creation of the SF/cluster is not an option.

System.IO.FileLoadException while using EntityFramework Core 2.0

I am using the In memory provider in a .Net 461 unit test project. I am using VS 2017.
var contextOptionsBuilder = new DbContextOptionsBuilder();
contextOptionsBuilder
.UseInMemoryDatabase("testmethod1");
var ctx = new ConfigStoreDbContext(contextOptionsBuilder.Options);
The packages.config contains the following package.
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
Here is the stack trace.
Test Name: TestMethod1
Test Outcome: Failed
Test Duration: 0:00:01.1170206
Result StackTrace:
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraph(InternalEntityEntry rootEntry, EntityState entityState, Boolean forceStateWhenUnknownKey)
at Microsoft.EntityFrameworkCore.DbContext.SetEntityState(InternalEntityEntry entry, EntityState entityState)
at Microsoft.EntityFrameworkCore.DbContext.SetEntityState[TEntity](TEntity entity, EntityState entityState)
at Microsoft.EntityFrameworkCore.DbContext.Add[TEntity](TEntity entity)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.Add(TEntity entity)
at Microsoft.ProjectConfig.Configuration.Sql.SqlConfigurationWriter`4.<AddOrUpdateSettingTypeImplAsync>d__7.MoveNext()
--- 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 Microsoft.ProjectConfig.Configuration.ConfigurationWriterBase`4.<AddOrUpdateSettingTypeAsync>d__4.MoveNext()
--- 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 Microsoft.ProjectConfig.Configuration.UnitTests.UnitTest1.<TestMethod1>d__0.MoveNext() in C:\Repos\ProjectConfig\UnitTestProject1\UnitTest1.cs:line 25
--- 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 Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)
Result Message:
Test method Microsoft.ProjectConfig.Configuration.UnitTests.UnitTest1.TestMethod1 threw exception:
System.IO.FileLoadException: Could not load file or assembly 'System.ValueTuple, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This issue is documented in the Entity Framework repository, here: https://github.com/aspnet/EntityFrameworkCore/issues/9046.

Service Fabric - "object is closed" exception via ActorProxy

I'm catching the following exception on my cluster, randomly when an actor calls another one via ActorProxy:
System.Fabric.FabricObjectClosedException: The object is closed. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x80071BFE
at System.Fabric.Interop.NativeRuntime.IFabricKeyValueStoreReplica6.CreateTransaction()
at System.Fabric.KeyValueStoreReplica.CreateTransactionHelper(KeyValueStoreTransactionSettings settings)
at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func1 func, String functionTag, String functionArgs)
--- End of inner exception stack trace ---
at System.Fabric.Interop.Utility.WrapNativeSyncInvoke[TResult](Func1 func, String functionTag, String functionArgs)
at Microsoft.ServiceFabric.Actors.Runtime.KvsActorStateProvider.<>c__DisplayClass14.b__13()
at Microsoft.ServiceFabric.Actors.Runtime.ActorStateProviderHelper.d__61.MoveNext()
--- 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 Microsoft.ServiceFabric.Actors.Runtime.ActorStateManager.<ContainsStateAsync>d__17.MoveNext()
--- 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 PosteItaliane.Sin.StateManagement.ObservableState.SingleValueWrapper1.d__2.MoveNext() in C:\Users\maurosag\Source\Repos\Equitalia3\SIN\PI.Sin.StateManagement\ObservableState\SingleValueWrapper.cs:line 21
--- 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 PosteItaliane.Sin.Utility.ServiceFabric.StatefulActor`1.get_State() ....
Searching on the web, i cannot figure out how to resolve it; the only discussions concern with Powershell exec:
“This means that this replica got demoted from primary to secondary. The client will re-resolve and reconnect to the new primary if you let the exception bubble up. The existing processing will drain on the primary. I am resolving the issue as "By Design". Please feel free to reopen if you still have question.”
Anyone can help me?
Thanks in advance.

TFS 2015 machine groups cannot be selected in build/deployment definition (vnext) after creation

We have a problem with a TFS 2015 installation, an upgrade from 2010. We ran into the following issue. This concerns a dry run, so we install everything on the same server, which is not a prefered method, we know.
• Installed new virtual server with Windows Server 2012 R2
• Added IIS feature
• Installed SQL server 2014
• Installed sharepoint foundation 2013 on the server
• Installed visual studio 2015 on the server
• Installed all the necessary .NET target frameworks
• Installed the prerequisites like MS Build tools 2015, Agents for Microsoft Visual Studio 2015
• Restored TFS2010 backups to new SQL server
• Installed tfs 2015 and ran the ‘Upgrade’ option in the setup
• Processed all the steps in configuration, like adding a build controller and build agent
• Dowloaded the Vso agent and ran the ‘ConfigureAgent.cmd’
• Configured the agent pool and queue in TFS
• Added an extra collection of team projects. So we have a collection of legacy upgraded projects from 2010, plus a collection of new team projects
• Administered the team projects, team members, etc.
• Created a XAML build definition, builds are done correctly on the server, tests are performed
However,
If I try to create a a new (non XAML) build definition using the deployment template (see images).
The problem occurs when we want to select a “Test Machine Group / Azure Resource Group”, for instance when selecting the location of testing. The select list is empty.
So we added machine groups using the ‘Manage’ option, and the machine group is available. However the dropdown list with machine groups stays empty, even after refresh (see images).
Next we checked the event logs fort his issue. On a refresh of the dropdownlist the following entries are made in the event log :
First :
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Microsoft-Team Foundation Server" Guid="{80761876-6844-47D5-8106-F8ED2AA8687B}" />
<EventID>0</EventID>
<Version>3</Version>
<Level>2</Level>
<Task>1</Task>
<Opcode>10</Opcode>
<Keywords>0x8000000000000001</Keywords>
<TimeCreated SystemTime="2016-04-12T09:09:21.717163200Z" />
<EventRecordID>59666</EventRecordID>
<Correlation ActivityID="{6AD40FD3-10BA-4A7E-B6D9-F6926072DAB4}" />
<Execution ProcessID="3376" ThreadID="6484" />
<Channel>Microsoft-Team Foundation Server/Debug</Channel>
<Computer>KTBSV021.KTB.local</Computer>
<Security UserID="S-1-5-21-2105344776-4230907741-261866850-3716" />
</System>
- <UserData>
- <Info TraceId="{00000001-0001-0001-0000-000000000000}" xmlns="http://schemas.microsoft.com/TeamFoundation/2010/Framework">
<Tracepoint>0</Tracepoint>
<ServiceHost>{87670F79-6386-4363-9960-73B634419263}</ServiceHost>
<ContextId>10085</ContextId>
<ProcessName>w3wp</ProcessName>
<Username>KTB\tmpadmin</Username>
<VSID>{9E83242F-9944-4CBD-AF10-EF2D449A03B1}</VSID>
<Service>Web-Api</Service>
<Method>TaskDefinitionWebApiProxy.QueryEndpoint</Method>
<Area>DistributedTask</Area>
<Layer>WebApiProxy</Layer>
<UserAgent>Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko</UserAgent>
<Uri>/tfs/Default/_apis/distributedtask/endpoint</Uri>
<Path />
<UniqueIdentifier>{A9646429-41CB-4137-A39A-D4E29EDDC389}</UniqueIdentifier>
<UserDefined />
<ExceptionType>System.Net.WebException</ExceptionType>
<Message>System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Microsoft.TeamFoundation.DistributedTask.Server.WebApiProxy.HttpRequestProxy.ExecuteRequest(HttpRequestMessage requestMessage, IList`1 sourceDefinitions, DataSource dataSource)</Message>
</Info>
</UserData>
</Event>
Second:
- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
<Provider Name="Microsoft-Team Foundation Server" Guid="{80761876-6844-47D5-8106-F8ED2AA8687B}" />
<EventID>0</EventID>
<Version>3</Version>
<Level>2</Level>
<Task>1</Task>
<Opcode>10</Opcode>
<Keywords>0x8000000000000001</Keywords>
<TimeCreated SystemTime="2016-04-12T09:09:21.717163200Z" />
<EventRecordID>59667</EventRecordID>
<Correlation ActivityID="{6AD40FD3-10BA-4A7E-B6D9-F6926072DAB4}" />
<Execution ProcessID="3376" ThreadID="6484" />
<Channel>Microsoft-Team Foundation Server/Debug</Channel>
<Computer>KTBSV021.KTB.local</Computer>
<Security UserID="S-1-5-21-2105344776-4230907741-261866850-3716" />
</System>
- <UserData>
- <Info TraceId="{00000001-0001-0001-0000-000000000000}" xmlns="http://schemas.microsoft.com/TeamFoundation/2010/Framework">
<Tracepoint>103200</Tracepoint>
<ServiceHost>{87670F79-6386-4363-9960-73B634419263}</ServiceHost>
<ContextId>10082</ContextId>
<ProcessName>w3wp</ProcessName>
<Username>KTB\tmpadmin</Username>
<VSID>{9E83242F-9944-4CBD-AF10-EF2D449A03B1}</VSID>
<Service>Web-Api</Service>
<Method>TaskDefinitionWebApiProxy.QueryEndpoint</Method>
<Area>DistributedTask</Area>
<Layer>TaskDefinitionWebApiProxy</Layer>
<UserAgent>Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko</UserAgent>
<Uri>/tfs/Default/_apis/distributedtask/endpoint</Uri>
<Path />
<UniqueIdentifier>{A9646429-41CB-4137-A39A-D4E29EDDC389}</UniqueIdentifier>
<UserDefined />
<ExceptionType>Microsoft.TeamFoundation.DistributedTask.WebApi.ServiceEndpointQueryFailedException</ExceptionType>
<Message>Microsoft.TeamFoundation.DistributedTask.WebApi.ServiceEndpointQueryFailedException: The remote server returned an error: (401) Unauthorized. at Microsoft.TeamFoundation.DistributedTask.Server.WebApiProxy.HttpRequestProxy.ExecuteRequest(HttpRequestMessage requestMessage, IList`1 sourceDefinitions, DataSource dataSource) at Microsoft.TeamFoundation.DistributedTask.Server.Controllers.TaskDefinitionWebApiProxyController.QueryEndpoint(TaskDefinitionEndpoint endpoint) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken) --- 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.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext() --- 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.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext() --- 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.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- 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.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() --- 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.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext() --- 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.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()</Message>
</Info>
</UserData>
</Event>
Fiddler reports it is the following request is failing :
POST http://localhost:8080/tfs/Default/_apis/distributedtask/endpoint HTTP/1.1
• Powershell Remote has been enabled on the server.
• The service account has been added to the role in the agent pool.
It is obviously a security issue. What are we forgetting or doing wrong ?
Your issue is kinda like this post. You may try the solution in this case to add TFS service account to C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys with full access so that the service can access all the certificates.
But first of all, try to re-deploy the agent with your account that should have been added as a team project collection administrator or an agent pool administrator.