Can not find compilation library location for package 'Newtonsoft.Json' - c#

Using Visual Studio for Mac (Community 7.3), I am trying to run the sample project from Lynda.com's "Learning ASP.NET Core MVC" Chapter 3 which introduces "Render HTML with Razor".
I builds find but when I try to load in browser I get the error below:
An unhandled exception occurred while processing the request.
InvalidOperationException: Can not find compilation library location
for package 'Newtonsoft.Json'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Stack Query Cookies Headers InvalidOperationException: Can not find
compilation library location for package 'Newtonsoft.Json'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
System.Linq.Enumerable+d__157.MoveNext()
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable
parts, MetadataReferenceFeature feature)
Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature(TFeature
feature)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.GetCompilationReferences()
System.Threading.LazyInitializer.EnsureInitializedCore(ref T
target, ref bool initialized, ref object syncLock, Func
valueFactory)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.get_CompilationReferences()
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRoslynCompilationService.Compile(RelativeFileInfo
fileInfo, string compilationContent)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.CreateCacheEntry(string
relativePath, string normalizedPath, Func compile)
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Razor.Internal.CompilerCache.GetOrAdd(string
relativePath, Func compile)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(string
relativePath)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet
expirationTokens, string relativePath, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext
expanderContext, ViewLocationCacheKey cacheKey)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext
actionContext, string pageName, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext
context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext
context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor.FindView(ActionContext
actionContext, ViewResult viewResult)
Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__32.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__31.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__29.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__23.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) System.Runtime.CompilerServices.TaskAwaiter.GetResult()
ExploreCalifornia.Startup+<>c+<b__3_0>d.MoveNext() in
Startup.cs
await next(); System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__6.MoveNext()
Show raw exception details

Related

C# Blazor - Fix "This connection was used with an ambient transaction..."

I added a timer in a Blazor page, so some data (pulled from database) can refresh every 5 seconds. It works fine when I'm on the page, but when I move to a different page and come back to the original one, I get this error:
"This connection was used with an ambient transaction. The original
ambient transaction needs to be completed before this connection can
be used outside of it" I've included the stack trace at the end
I've tried to dispose the Timer when the page disposes, but it didn't solve it. It looks like this issue is due to how the DB context is registered in the Dependency Injection container, but
Here is the C# code of my page. It calls the main service, who in turns gets data through a repository.
#functions {
protected Dictionary<int, int> RunningTaskProcessQueueCountDictionary;
protected Dictionary<int, int> PendingTaskProcessQueueCountDictionary;
protected Timer CountRefreshTimer = null;
protected override async Task OnInitAsync()
{
CountRefreshTimer = new Timer(new TimerCallback(async _ =>
{
await RefreshCount();
await base.Invoke(StateHasChanged);
}), null, 0, 5000);
}
private async Task RefreshCount()
{
RunningTaskProcessQueueCountDictionary = await mainService.GetRunningTaskProcessQueueCountByTaskAppAsync(null);
PendingTaskProcessQueueCountDictionary = await mainService.GetPendingTaskProcessQueueCountByTaskAppAsync(null);
}
public void Dispose()
{
if (CountRefreshTimer != null)
{
CountRefreshTimer.Dispose();
}
}
}
Here is an extract of the startup.cs where DB context is registered:
// Register the DB Context
var connection = Configuration.GetConnectionString("SQL01.xxx");
services.AddDbContext<SQL01xxxContext>(options => options.UseSqlServer(connection));
// Register all repositories and services (using Scrutor)
services.Scan(scan =>
scan.FromAssemblies(typeof(IMainService).Assembly, typeof(ITaskAppRepository).Assembly)
.AddClasses()
.AsMatchingInterface()
.WithScopedLifetime());
services.AddScoped<DbContext, SQL01xxxContext>();
services.AddScoped<IUnitOfWork<SQL01xxxContext>, UnitOfWork<SQL01xxxContext>>();
This is the stacktrace of the error
System.InvalidOperationException HResult=0x80131509 Message=This
connection was used with an ambient transaction. The original ambient
transaction needs to be completed before this connection can be used
outside of it. Source=Microsoft.EntityFrameworkCore.Relational
StackTrace: at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.HandleAmbientTransactions()
at
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.d__42.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.d__12.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.<ExecuteAsync>d__72.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncQueryingEnumerable1.AsyncEnumerator.d__11.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at
System.Linq.AsyncEnumerable.SelectEnumerableAsyncIterator2.d__7.MoveNext()
in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Select.cs:line 106
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at
System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult()
at
System.Linq.AsyncEnumerable.AsyncIterator1.d__10.MoveNext()
in
D:\a\1\s\Ix.NET\Source\System.Interactive.Async\AsyncIterator.cs:line
112 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.d__5.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at System.Linq.AsyncEnumerable.d__63.MoveNext()
in D:\a\1\s\Ix.NET\Source\System.Interactive.Async\Aggregate.cs:line
120 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
SIQC.Enterprise.GenericRepository.Common.IQueryableExtensions.d__11.MoveNext()
in C:\TFS\[...]\IQueryableExtensions.cs:line 28 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
SIQC.Enterprise.GenericRepository.RepositoryBase.ReadOnlyRepository1.<GetAsync>d__12.MoveNext()
in C:\TFS\[...]\ReadOnlyRepository.cs:line 174 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
ToolsWebManagementData.IntravexV21.Repository.TaskProcessQueueRepository.d__2.MoveNext()
in C:\TFS[...]\TaskProcessQueueRepository.cs:line 46 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at
TWMBlazorSSB.Services.MainService.<GetRunningTaskProcessQueueCountByTaskAppAsync>d__21.MoveNext()
in C:\TFS\[...]\MainService.cs:line 79 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at TWMBlazorSSB.Pages.TaskApp.TaskApps.d__7.MoveNext()
in C:\TFS[...]\TaskApps.razor:line 91 at
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at
TWMBlazorSSB.Pages.TaskApp.TaskApps.<b__6_0>d.MoveNext()
in C:\TFS[...]\TaskApps.razor:line 79
Any help would be appreciated.
Thanks
It looks like this issue is due to how the DB context is registered
That is correct. This is because AddDbContext<> uses (as default) ServiceLifetime.Scoped. But there is no useful Scope.
This is still under discussion by the Blazor team, maybe wait for the next preview before considering a workaround.
But I see it is now bumped to preview-9.

Windows Azure Table Storage Serialization Error in Bot Framework v3

I am using Windows.Azure.Storage .NET Client library (v 9.3.2) to work with Azure Storage Tables. I am using this in Bot Framework v3. Bot Framework requires all entity classes to be [Serializable].
My domain classes inherit from TableEntity and look like the following:
[Serializable]
public class FAQContent : TableEntity
{
public string Message
{
get;set;
}
public string Type
{ get; set; }
public string Mime
{ get; set; }
On querying the Azure table, I am getting exceptions like the following:
System.Runtime.Serialization.SerializationException: Type
'Microsoft.WindowsAzure.Storage.Table.TableEntity' in Assembly
'Microsoft.WindowsAzure.Storage, Version=9.3.2.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
at
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType
type) at
System.Runtime.Serialization.FormatterServices.<>c__DisplayClass9_0.b__0(MemberHolder
_) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey
key, Func2 valueFactory) at
System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type
type, StreamingContext context) at
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
at
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Type
objectType, ISurrogateSelector surrogateSelector, StreamingContext
context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter
converter, SerializationBinder binder) at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, WriteObjectInfo memberObjectInfo)
at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo
objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) at
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream
serializationStream, Object graph, Header[] headers, Boolean fCheck)
at
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream
serializationStream, Object graph) at
Microsoft.Bot.Builder.Internals.Fibers.FormatterStore1.Microsoft.Bot.Builder.Internals.Fibers.IStore.Save(T
item) at
Microsoft.Bot.Builder.Internals.Fibers.ErrorResilientStore1.Microsoft.Bot.Builder.Internals.Fibers.IStore.Save(T
item) at
Microsoft.Bot.Builder.Internals.Fibers.FactoryStore1.Microsoft.Bot.Builder.Internals.Fibers.IStore.Save(T
item) at
Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d__23.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.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.d__3.MoveNext()---
End of stack trace from previous location where exception was thrown
--- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task) at
Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop`1.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
Microsoft.Bot.Builder.Dialogs.Internals.EventLoopDialogTask.d__3.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.Bot.Builder.Dialogs.Internals.SetAmbientThreadCulture.d__3.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.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask.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
Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.MoveNext()--- End of stack trace from previous location where exception was thrown
--- at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d__3.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.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.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
Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.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
Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.d__5.MoveNext()--- End of stack trace from previous location where exception was thrown
--- at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.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
Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.d__3.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.Bot.Builder.Dialogs.Conversation.d__11.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.Bot.Builder.Dialogs.Conversation.d__6.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 Service_Bot.MessagesController.d__1.MoveNext()
Can someone suggest what could be going wrong?
Cheers
Abhishek

Azure Data Factory -Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11

I am running into an error trying to run a program thought ADF. The code runs fine on my console.The error is below.
Error in Activity: Unknown error in module: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) at Microsoft.Azure.Services.AppAuthentication.WindowsAuthenticationAzureServiceTokenProvider.<GetTokenAsync>d__5.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Azure.Services.AppAuthentication.WindowsAuthenticationAzureServiceTokenProvider.GetTokenAsync(String resource, String authority) at Microsoft.Azure.Services.AppAuthentication.NonInteractiveAzureServiceTokenProviderBase.<GetTokenAsync>d__3.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.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider.<GetAccessTokenAsyncImpl>d__14.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.Azure.KeyVault.KeyVaultCredential.<PostAuthenticate>d__11.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.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Microsoft.Azure.KeyVault.KeyVaultCredential.<ProcessHttpRequestAsync>d__13.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.Azure.KeyVault.KeyVaultClient.<GetSecretWithHttpMessagesAsync>d__65.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.Azure.KeyVault.KeyVaultClientExtensions.<GetSecretAsync>d__13.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.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult() at CRMEMAILLOOKUP.Lookup.<GetSecretCertificateAsync>
Part of my code I am retrieving a certificate from Azure Key Vault, my suspicion is this bit of code is causing the conflict. I am using Nuget packages Microsoft.Azure.Service.AppAuthentication , Microsoft.Azure.KeyVault and Microsoft.Azure.KeyVault.Webkey. Are these packages compatible with ADF v1 or is the Microsoft.IdentityModel.Clients.ActiveDirectory reference error caused by these packages?
public static async Task<X509Certificate2> GetSecretCertificateAsync(string secretName)
{
var provider = new AzureServiceTokenProvider();
var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(provider.KeyVaultTokenCallback));
var secretBundle = await client.GetSecretAsync($"{secretName}").ConfigureAwait(false);
var pfx = secretBundle.Value; var bytes = Convert.FromBase64String(pfx);
var coll = new X509Certificate2Collection();
coll.Import(bytes, null, X509KeyStorageFlags.UserKeySet | X509KeyStorageFlags.MachineKeySet);
return coll[3];
}

ASP.NET Identity does not authenticate user after successful sign in

I am using using the "default" authentication code generated by Visual Studio, at the creation of a new project.
The authentication (using local accounts) goes well... in most of the cases. In some cases (I cannot establish a pattern), even if the result of the sign-in is "success", the user does not appear to be authenticated and it's not being redirected to the start page. This is the code:
// Validate the user password
var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
var signinManager = Context.GetOwinContext().GetUserManager<ApplicationSignInManager>();
var result = signinManager.PasswordSignIn(Email.Text, Password.Text, true, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
BLL.HelperMethods.LogInfo("Inside 'switch', on branch 'Success'");
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
break;
...
}
I can see in the log file that the result of the authentication is success. Even so, the page is not being redirected and the user is not being authenticated.
Thank you.
LATER EDIT:
I think that the following error, which appears from time to time is related to this problem:
EXCEPTION TYPE: System.Web.HttpException
EXCEPTION MESSAGE: Server cannot append header after HTTP headers have been sent.
SOURCE: Global.asax.cs -> Application_Error
STACK TRACE: at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace)
at System.Web.HttpHeaderCollection.Set(String name, String value)
at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.Set(String key, String[] values)
at Microsoft.Owin.Host.SystemWeb.CallHeaders.AspNetResponseHeaders.set_Item(String key, String[] value)
at Microsoft.Owin.Infrastructure.OwinHelpers.SetHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
at Microsoft.Owin.Infrastructure.OwinHelpers.AppendHeaderUnmodified(IDictionary`2 headers, String key, String[] values)
at Microsoft.Owin.HeaderDictionary.AppendValues(String key, String[] values)
at Microsoft.Owin.Infrastructure.ChunkingCookieManager.AppendResponseCookie(IOwinContext context, String key, String value, CookieOptions options)
at Microsoft.Owin.Security.Cookies.CookieAuthenticationHandler.<ApplyResponseGrantAsync>d__f.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.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseCoreAsync>d__b.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.Owin.Security.Infrastructure.AuthenticationHandler.<ApplyResponseAsync>d__8.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.Owin.Security.Infrastructure.AuthenticationHandler.<TeardownAsync>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 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware`1.<Invoke>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 Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.<Invoke>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 Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.<Invoke>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 Microsoft.AspNet.Identity.Owin.IdentityFactoryMiddleware`2.<Invoke>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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.<RunApp>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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.<DoFinalWork>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)
at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)
at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I have found another question which describes the same problem. AND some workarounds. It seems to be a bug. You can find the solution here - ASP.NET_SessionId + OWIN Cookies do not send to browser

SignalR + Redis backplane = System.InvalidOperationException: The queue is full

I use SignalR with redis backplane. To set up it, I use simple code
var redisConfig = new RedisScaleoutConfiguration("connectionString","eventKey");
GlobalHost.DependencyResolver.UseRedis(redisConfig);
Everything worked fine,but than I began to get following exceptions.
Unhandled exception in Portal UI:System.InvalidOperationException: The queue is full. at Microsoft.AspNet.SignalR.Messaging.ScaleoutStream.Send(Func2 send, Object state) at Microsoft.AspNet.SignalR.Infrastructure.Connection.Send(ConnectionMessage message) at Microsoft.AspNet.SignalR.Transports.TransportConnectionExtensions.SendCommand(ITransportConnection connection, String connectionId, CommandType commandType) at Microsoft.AspNet.SignalR.Transports.ForeverTransport.ProcessRequestCore(ITransportConnection connection) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequestPostGroupRead(HostContext context, String groupsToken) at Microsoft.AspNet.SignalR.TaskAsyncHelper.FromMethod[T1,T2,T3,TResult](Func4 func, T1 arg1, T2 arg2, T3 arg3) --- 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.Owin.Mapping.MapMiddleware.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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.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 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware1.<Invoke>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 Microsoft.Owin.Security.Infrastructure.AuthenticationMiddleware1.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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContextStage.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 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) at System.Web.HttpApplication.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
I looked into redis cache . It seems that it's ok. It has enough space.
What doest 'The queue is full' mean? What is this queue? How can I avoid such exceptions?

Categories