Bug 36157 - Keypair was disposed using IdentityServer3
Summary: Keypair was disposed using IdentityServer3
Status: CONFIRMED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-23 12:34 UTC by Lorenzo Delana
Modified: 2017-09-06 16:44 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 36157 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Lorenzo Delana 2015-11-23 12:34:32 UTC
Just tried the SelfHost (Minimal) app from IdentityServer3 https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/SelfHost%20(Minimal) and it fails while it works correctly under windows.

Follow execution log:

18:11 [WRN] (IdentityServer3.Core.Configuration.IdentityServerServiceFactory)
 AuthorizationCodeStore not configured - falling back to InMemory
18:11 [WRN] (IdentityServer3.Core.Configuration.IdentityServerServiceFactory)
 TokenHandleStore not configured - falling back to InMemory
18:11 [WRN] (IdentityServer3.Core.Configuration.IdentityServerServiceFactory)
 ConsentStore not configured - falling back to InMemory
18:11 [WRN] (IdentityServer3.Core.Configuration.IdentityServerServiceFactory)
 RefreshTokenStore not configured - falling back to InMemory

Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Keypair was disposed'.
  at Mono.Security.Cryptography.RSAManaged.get_KeySize () <0xb4ad5a4c + 0x00084> in <filename unknown>:0
  at System.Security.Cryptography.RSACryptoServiceProvider.get_KeySize () <0xb4c21874 + 0x00033> in <filename unknown>:0
  at Owin.UseIdentityServerExtension+<DoStartupDiagnosticsAsync>d__0.MoveNext () <0xb3716418 + 0x003af> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.ThrowIfExceptional (Boolean includeTaskCanceledExceptions) <0xb4a600ec + 0x0003c> in <filename unknown>:0
  at System.Threading.Tasks.Task.Wait (Int32 millisecondsTimeout, CancellationToken cancellationToken) <0xb4a61a20 + 0x000d3> in <filename unknown>:0
  at System.Threading.Tasks.Task.Wait () <0xb4a61804 + 0x00023> in <filename unknown>:0
  at Owin.UseIdentityServerExtension.UseIdentityServer (IAppBuilder app, IdentityServer3.Core.Configuration.IdentityServerOptions options) <0xb38c8220 + 0x0025b> in <filename unknown>:0
  at SelfHost.Startup.Configuration (IAppBuilder appBuilder) <0xb424b4d8 + 0x000f3> in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0xb4baf94c + 0x000ab> in <filename unknown>:0
---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Keypair was disposed'.
  at Mono.Security.Cryptography.RSAManaged.get_KeySize () <0xb4ad5a4c + 0x00084> in <filename unknown>:0
  at System.Security.Cryptography.RSACryptoServiceProvider.get_KeySize () <0xb4c21874 + 0x00033> in <filename unknown>:0
  at Owin.UseIdentityServerExtension+<DoStartupDiagnosticsAsync>d__0.MoveNext () <0xb3716418 + 0x003af> in <filename unknown>:0 <---

  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0xb4baf94c + 0x000e4> in <filename unknown>:0
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0xb49804e8 + 0x00047> in <filename unknown>:0
  at Owin.Loader.DefaultLoader+<>c__DisplayClass12.<MakeDelegate>b__b (IAppBuilder builder) <0xb424b448 + 0x0006b> in <filename unknown>:0
  at Owin.Loader.DefaultLoader+<>c__DisplayClass1.<LoadImplementation>b__0 (IAppBuilder builder) <0xb424b280 + 0x000fb> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp (Microsoft.Owin.Hosting.Engine.StartContext context) <0xb4250f78 + 0x001bf> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) <0xb685e0b8 + 0x000db> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6894180 + 0x00053> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6891510 + 0x0008f> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) <0xb68906b0 + 0x0005f> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6b94960 + 0x00023> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start[TStartup] (Microsoft.Owin.Hosting.StartOptions options) <0xb6b94738 + 0x00047> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start[TStartup] (System.String url) <0xb6b94498 + 0x0002f> in <filename unknown>:0
  at SelfHost.Program.Main (System.String[] args) <0xb6b86f50 + 0x00077> in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Keypair was disposed'.
  at Mono.Security.Cryptography.RSAManaged.get_KeySize () <0xb4ad5a4c + 0x00084> in <filename unknown>:0
  at System.Security.Cryptography.RSACryptoServiceProvider.get_KeySize () <0xb4c21874 + 0x00033> in <filename unknown>:0
  at Owin.UseIdentityServerExtension+<DoStartupDiagnosticsAsync>d__0.MoveNext () <0xb3716418 + 0x003af> in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.ThrowIfExceptional (Boolean includeTaskCanceledExceptions) <0xb4a600ec + 0x0003c> in <filename unknown>:0
  at System.Threading.Tasks.Task.Wait (Int32 millisecondsTimeout, CancellationToken cancellationToken) <0xb4a61a20 + 0x000d3> in <filename unknown>:0
  at System.Threading.Tasks.Task.Wait () <0xb4a61804 + 0x00023> in <filename unknown>:0
  at Owin.UseIdentityServerExtension.UseIdentityServer (IAppBuilder app, IdentityServer3.Core.Configuration.IdentityServerOptions options) <0xb38c8220 + 0x0025b> in <filename unknown>:0
  at SelfHost.Startup.Configuration (IAppBuilder appBuilder) <0xb424b4d8 + 0x000f3> in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0xb4baf94c + 0x000ab> in <filename unknown>:0
---> (Inner Exception #0) System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Keypair was disposed'.
  at Mono.Security.Cryptography.RSAManaged.get_KeySize () <0xb4ad5a4c + 0x00084> in <filename unknown>:0
  at System.Security.Cryptography.RSACryptoServiceProvider.get_KeySize () <0xb4c21874 + 0x00033> in <filename unknown>:0
  at Owin.UseIdentityServerExtension+<DoStartupDiagnosticsAsync>d__0.MoveNext () <0xb3716418 + 0x003af> in <filename unknown>:0 <---

  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0xb4baf94c + 0x000e4> in <filename unknown>:0
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0xb49804e8 + 0x00047> in <filename unknown>:0
  at Owin.Loader.DefaultLoader+<>c__DisplayClass12.<MakeDelegate>b__b (IAppBuilder builder) <0xb424b448 + 0x0006b> in <filename unknown>:0
  at Owin.Loader.DefaultLoader+<>c__DisplayClass1.<LoadImplementation>b__0 (IAppBuilder builder) <0xb424b280 + 0x000fb> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp (Microsoft.Owin.Hosting.Engine.StartContext context) <0xb4250f78 + 0x001bf> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Engine.HostingEngine.Start (Microsoft.Owin.Hosting.Engine.StartContext context) <0xb685e0b8 + 0x000db> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6894180 + 0x00053> in <filename unknown>:0
  at Microsoft.Owin.Hosting.Starter.HostingStarter.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6891510 + 0x0008f> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.StartImplementation (IServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) <0xb68906b0 + 0x0005f> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start (Microsoft.Owin.Hosting.StartOptions options) <0xb6b94960 + 0x00023> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start[TStartup] (Microsoft.Owin.Hosting.StartOptions options) <0xb6b94738 + 0x00047> in <filename unknown>:0
  at Microsoft.Owin.Hosting.WebApp.Start[TStartup] (System.String url) <0xb6b94498 + 0x0002f> in <filename unknown>:0
  at SelfHost.Program.Main (System.String[] args) <0xb6b86f50 + 0x00077> in <filename unknown>:0
Comment 1 Lorenzo Delana 2015-11-23 12:38:32 UTC
The correct link to clone the sample repo is the follow : https://github.com/IdentityServer/IdentityServer3.Samples.git
Comment 2 João Matos 2015-12-07 16:52:19 UTC
I can reproduce this problem.

Here's the stack trace from where the object is being originally disposed.

I've CC'd a few people who have worked on this code before, any ideas?

Mono.Security.Cryptography.RSAManaged.Dispose(bool disposing) in /Users/joao/Dev/mono/mcs/class/Mono.Security/Mono.Security.Cryptography/RSAManaged.cs:409
System.Security.Cryptography.AsymmetricAlgorithm.Clear() in /Users/joao/Dev/mono/external/referencesource/mscorlib/system/security/cryptography/asymmetricalgorithm.cs:32
System.Security.Cryptography.RSACryptoServiceProvider.Dispose(bool disposing) in /Users/joao/Dev/mono/mcs/class/corlib/System.Security.Cryptography/RSACryptoServiceProvider.cs:376
System.Security.Cryptography.AsymmetricAlgorithm.Clear() in /Users/joao/Dev/mono/external/referencesource/mscorlib/system/security/cryptography/asymmetricalgorithm.cs:32
System.Security.Cryptography.AsymmetricAlgorithm.Dispose() in /Users/joao/Dev/mono/external/referencesource/mscorlib/system/security/cryptography/asymmetricalgorithm.cs:28
IdentityServer3.Core.Extensions.X509Certificate2Extensions.IsPrivateAccessAllowed(System.Security.Cryptography.X509Certificates.X509Certificate2 cert) in 
Owin.UseIdentityServerExtension.DoStartupDiagnosticsAsync() in 
System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start<Owin.UseIdentityServerExtension.<DoStartupDiagnosticsAsync>d__0>(Owin.UseIdentityServerExtension stateMachine) in /Users/joao/Dev/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:316
Owin.UseIdentityServerExtension.DoStartupDiagnosticsAsync(IdentityServer3.Core.Configuration.IdentityServerOptions options, IdentityServer3.Core.Services.Default.EventServiceDecorator eventSvc) in 
Owin.UseIdentityServerExtension.UseIdentityServer(Microsoft.Owin.Builder.AppBuilder app, IdentityServer3.Core.Configuration.IdentityServerOptions options) in 
SelfHost.Startup.Configuration(Microsoft.Owin.Builder.AppBuilder appBuilder) in /Users/joao/Dev/IdentityServer3.Samples/source/SelfHost (Minimal)/SelfHost/Startup.cs:25
System.Reflection.MonoMethod.InternalInvoke() in 
Owin.Loader.DefaultLoader.(Microsoft.Owin.Builder.AppBuilder builder) in 
Owin.Loader.DefaultLoader.(Microsoft.Owin.Builder.AppBuilder builder) in 
Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(Microsoft.Owin.Hosting.Engine.StartContext context) in 
Microsoft.Owin.Hosting.Engine.HostingEngine.Start(Microsoft.Owin.Hosting.Engine.StartContext context) in 
Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(Microsoft.Owin.Hosting.StartOptions options) in 
Microsoft.Owin.Hosting.Starter.HostingStarter.Start(Microsoft.Owin.Hosting.StartOptions options) in 
Microsoft.Owin.Hosting.WebApp.StartImplementation(Microsoft.Owin.Hosting.Services.ServiceProvider services, Microsoft.Owin.Hosting.StartOptions options) in 
Microsoft.Owin.Hosting.WebApp.Start(Microsoft.Owin.Hosting.StartOptions options) in 
Microsoft.Owin.Hosting.WebApp.Start<SelfHost.Startup>(Microsoft.Owin.Hosting.StartOptions options) in 
Microsoft.Owin.Hosting.WebApp.Start<SelfHost.Startup>(string url) in 
SelfHost.Program.Main(string[] args) in /Users/joao/Dev/IdentityServer3.Samples/source/SelfHost (Minimal)/SelfHost/Program.cs:20