RSACryptoServiceProvider.ImportParameters ObjectDisposedException - .net-4.0

We have a webservice we would like to sign an incoming request and send it further. We are using the static object of System.Security.Cryptography.RSACryptoServiceProvider and every instance is using the same static object to sign it. I read on microsoft that the static object is thread safe for this class.
Problem is that on heavy load on webservice, the signing fails with below exception:
`Exception Type: System.ObjectDisposedException
Message: Safe handle's handle field can only be set if the safe handle is not closed and has a ref count of 1.
ObjectName:
Data: System.Collections.ListDictionaryInternal
TargetSite: Void _ImportKey(System.Security.Cryptography.SafeProvHandle, Int32, System.Security.Cryptography.CspProviderFlags, System.Object, System.Security.Cryptography.SafeKeyHandle ByRef)
HelpLink: NULL
Source: mscorlib
StackTrace Information
****************************
at System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
at System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)`

Related

How do I Provision a Transport Handler for IoTHub?

I am trying to connect to IoTHub to provision my device.
I am in a Blazor WASM app.
I have created the Security Provider Symmetric Key via:
SecurityProvider symmetricKeyProvider = new SecurityProviderSymmetricKey(parameters.DeviceId, parameters.DeviceSymmetricKey, null);
However my next line I call:
ProvisioningTransportHandler mqttTransportHandler = new ProvisioningTransportHandlerMqtt(TransportFallbackType.TcpOnly);
I have tried it with both the TcpOnly fallback along with not passing in any fallback and both give me the same error. The exception is:
Error provisioning device: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt' threw an exception.
---> System.InvalidOperationException: failed to create a child event loop.
---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Threading.Thread.Start()
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval, IQueue`1 taskQueue)
at DotNetty.Common.Concurrency.SingleThreadEventExecutor..ctor(IEventExecutorGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent, String threadName, TimeSpan breakoutInterval)
at DotNetty.Transport.Channels.SingleThreadEventLoop..ctor(IEventLoopGroup parent)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup.<>c.<.cctor>b__24_0(IEventLoopGroup group)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
--- End of inner exception stack trace ---
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor(Func`2 eventLoopFactory, Int32 eventLoopCount)
at DotNetty.Transport.Channels.MultithreadEventLoopGroup..ctor()
at Microsoft.Azure.Devices.Provisioning.Client.Transport.ProvisioningTransportHandlerMqtt..cctor()

The resource identifier failed to decrypt

We are hosting a site that has sitefinity, the site is crashing frequently and getting the error given below:
============================
Event code: 3012
Event message: An error occurred processing a web or script resource request. The resource identifier failed to decrypt.
Event time: 8/4/2016 1:09:19 PM
Event time (UTC): 8/4/2016 6:09:19 PM
Event ID: 9ed7856e9baa479f944599104bda8f46
Event sequence: 1265
Event occurrence: 6
Event detail code: 0
Exception information:
Exception type: HttpException
Exception message: Unable to validate data.
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData)
at System.Web.UI.Page.DecryptString(String s, Purpose purpose)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
Stack trace: at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData)
at System.Web.UI.Page.DecryptString(String s, Purpose purpose)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
+++++++++++++++++
I have already implemented the steps given in the URL:
http://www.sitefinity.com/developer-network/forums/general-discussions-/event-code-3012
Please let me know if you need any additional logs
Please advice.
Regards,
Set machine decryption key same at all application servers.
https://msdn.microsoft.com/en-us/library/w8h3skw9(v=vs.100).aspx

stack in AtlAdvise trying to create a connection between OPC server and the client (callback object)

Create Instance of Callback Object using an ATL template
CComObject<COPCDataCallback>::CreateInstance(&pCOPCDataCallback);
pCbUnk = pCOPCDataCallback->GetUnknown();
it stacked at
HRESULT hRes = AtlAdvise(m_IOPCGroupStateMgt, // [in] IUnknown Interface of the Connection Point
pCbUnk, // [in] IUnknown Interface of the Callback object
IID_IOPCDataCallback,// [in] Connection Point ID: The OPC Data Callback
m_dwAdvise // [out] Cookie that that uniquely identifies the connection
);
unhandled exception at XXXX ntdll.dll
before that I added ATL support to the MFC project
https://stackoverflow.com/a/8046824/4270170
any ideas to solve this issue?
thanks.
It seems to be my fault that the type of the fourth param of AtlAdvise is DWORD,but there is something wrong with this param I set.And now everything goes well.Thank you all.

CommunicationException in processing Array function

I am testing interaction between server and client app on single desktop and having issue with processing Array. My interface looks next
<ServiceContract>
Public Interface IMyService
<OperationContract>
Function GetData() As Array
End Interface
Server side implementation, is next
Public Function GetData() As Array Implements IMyService.GetData
Return {1, 2, 3, 4, 5, 6, 7, 8}
End Function
Client side code, is next
Shared Function GetData() As Array
Dim channel As IMyService = Nothing
Try
channel = ChannelFactory(Of IMyService).CreateChannel(New NetTcpBinding, address)
Return channel.GetData()
Finally
If channel IsNot Nothing Then
CType(channel, IClientChannel).Close()
End If
End Try
End Function
I am getting next exception upon executing Return channel.GetData(), and I don't have an issue with other interface functions that returns simple types (double, integer, etc.). My server app is self hosting WCF service.
System.ServiceModel.CommunicationException occurred
HResult=-2146233087
Message=The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9270000'.
Source=mscorlib
StackTrace:
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
InnerException: System.Net.Sockets.SocketException
ErrorCode=10054
HResult=-2147467259
Message=An existing connection was forcibly closed by the remote host
NativeErrorCode=10054
Source=System
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
InnerException:
Try to use List(Of Integer) type instead of array. It seems it's untyped (unfortunately, I am not vb dev.)
Or set a ServiceKnownType attribute:
<ServiceContract>
Public Interface IMyService
<OperationContract>
<ServiceKnownType(GetType(Integer()))>
Function GetData() As Array
End Interface
By the way to simplify the process of investigating WCF issue it's useful to add error handling:
Error handling
For you case it's exception: Type 'System.Int32[]' with data contract name 'ArrayOfint:http://schemas.microsoft.com/2003/10/Serialization/Arrays' is not expected. Consider using a DataContractResolver or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.

Application.UnhandledException and original exception message

I'm trying to access original exception which caused UnhandledException but all I see is text contained at UnhandledExceptionEventArgs.Message property;
For example:
I have view with button with click handler:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
throw new NullReferenceException("Test exc");
}
At App constructor I have subscribed to UnhandledException exception
this.UnhandledException += App_UnhandledException;
private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.Exception.ToString());
}
As a result I have no option to get original exception text "Test exc". All I have is
Message = System.NullReferenceException at
W8.Controls.SearchControl.Button_Click_1(Object sender,
RoutedEventArgs e)
Exception = System.NullReferenceException: Object reference not set to
an instance of an object.
Thanks in advance for advise!
There are some limitations in what gets propagated to a UnhandledException. As documented:
Another limitation is that the UnhandledException event arguments
don’t contain as much detail as the original exception. Whenever
possible, if the application requires specific processing of a certain
exception, it’s always better to catch the exception as it propagates,
since more detail will be available. The UnhandledException event
arguments expose an exception object through the Exception property.
However, the type, message, and stack trace of this exception object
are not guaranteed to match those of the original exception that was
raised. The event arguments also expose a Message property. In most
cases, this will contain the message of the originally raised
exception.