Get “Padding is Invalid and cannot be removed” in ASP.NET - asp.net

I'm seeing this error a lot in my log lately on my prod. I've searched over the net on this error. I saw some notes like this, this or this. The bottom line on all of them is that I should set machineKey. But I already have machineKey set!
Like that:
<machineKey decryption="AES"
validation="SHA1"
decryptionKey="64 hex key"
validationKey="other 64 hex key"/>
Also I'm on web farm server and my application is on asp.net 3.5.
I'm pretty hopeless about this problem =\ How can I solve this?
Thanks.
EDIT:
Here is a full log:
Time: 04/07/2011 19:52:25
MESSAGE: Padding is invalid and cannot be removed.
HTTP_REFERER:
SOURCE: mscorlib
FORM:
QUERYSTRING: d=iAY45pNWTDkOra20F86mL9NBCe-wjxevTFjlNNxafjqLF0Aug2JmvB-c_8JQN4XnDIU1UJTmY2MC1xuySMKscg2&t=633851453303086250
TARGETSITE: Int32 DecryptData(Byte[], Int32, Int32, Byte[] ByRef, Int32, System.Security.Cryptography.PaddingMode, Boolean)
STACKTRACE: at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType)
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

A recent ASP.Net patch changed the encryption format.
Make sure that every server in the farm is fully updated.

Related

System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2725318

i am getting an error while page reload on a dropdownlist option chang
[InvalidOperationException: Operation is not valid due to the current state of the object.]
System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2725318
System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
System.Web.HttpRequest.FillInFormCollection() +148
[HttpException (0x80004005): The URL-encoded form data is not valid.]
System.Web.HttpRequest.FillInFormCollection() +206
System.Web.HttpRequest.get_Form() +68
System.Web.HttpRequest.get_HasForm() +8807191
System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
System.Web.UI.Page.DeterminePostBackMode() +63
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133
I had found some articles saying if you increase the value of MaxHttpCollectionKeys in the app setting it will work but it doesn't seem to work for me
I have tried various different values extending to the below value but none work of
<add key="aspnet:MaxHttpCollectionKeys" value="900000000000000000000000000000" />
you help is most appreciated

Having a hard time tracking down a process that is crashing my app pool

So I have an app that keeps crashing out and it's not leaving any application logs. When I finally went and looked in the event viewer for that server (a server 2003 box), I found this error (The even source was ASP.NET 4.0.30319.0)
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/2053196604/Root
Process ID: 24428
Exception: System.IO.FileLoadException
Message: Could not load file or assembly
'Microsoft.Practices.EnterpriseLibrary.Validation, Version=5.0.505.0,
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)
StackTrace: Server stack trace: at
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName,
ObjectHandleOnStack type) at
System.RuntimeTypeHandle.GetTypeByName(String name, Boolean
throwOnError, Boolean ignoreCase, Boolean reflectionOnly,
StackCrawlMark& stackMark, Boolean loadTypeFromPartialName) at
System.RuntimeType.GetType(String typeName, Boolean throwOnError,
Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName) at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.AddValidationExtension()
at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator..ctor(IUnityContainer
container) at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.CreateDefaultContainer(IConfigurationSource
configurationSource) at
Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.SetCurrentContainerIfNotSet()
at Microsoft.Practices.EnterpriseLibrary.Logging.Logger.get_Writer()
at Apriva.WebApi.Shared.Logging.DefaultLogWriter.Log(Object message,
TraceEventType severity, LogEntry& entry, String category, HttpContext
context) at
Apriva.WebApi.Shared.Logging.DefaultLogWriter.Info(Object message,
String category, HttpContext context) at
System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr
md, Object[] args, Object server, Int32 methodPtr, Boolean
fExecuteInContext, Object[]& outArgs) at
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage
msg, IMessageSink replySink)
Exception rethrown at [0]: at
System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message
reqMsg, Boolean bProxyCase) at
System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed,
MessageData& msgData) at
Apriva.WebApi.Shared.Logging.Logger.LogDelegate.EndInvoke(IAsyncResult
result) at
Apriva.WebApi.Shared.Logging.Logger.LogAsyncComplete(IAsyncResult ar)
at
System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage
msg) at
System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage
msg, IMessageSink replySink) at
System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
at
System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object
o) at
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object
state) at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx) at
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch() at
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
For more information, see Help and Support Center at
When I check the processes in the task manager, this PID isn't present. I figure it's because it is a w3wp process. So I go to command prompt and run iisapp.vbs and it returns a single process with a different PID.
The error seems to imply that there is a config reference to a different version of the enterprise library for validation when the version that was found was v5.0.505.0 and while my projects have plenty of references to the enterprise library, none refer to the validation package.
So my question is -- does anyone have any insight into where I should look next? I was trying to use the PID to at least see which application was causing the error, but that doesn't seem to be getting me anywhere.
Analysis:
From stack trace its clear that reference chain is:
Apriva.WebApi.Shared.Logging.DefaultLogWriter => Microsoft.Practices.EnterpriseLibrary.Logging.Logger => Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer => Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator.
Method "AddValidationExtension" of type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.Unity.UnityContainerConfigurator needs type from 'Microsoft.Practices.EnterpriseLibrary.Validation assembly with signature
Possible steps find out root cause:
Open solution in visual studio.
Go to Edit Menu-> Find and Replace->Find in Files
Search for Microsoft.Practices.EnterpriseLibrary.Validation with Find options->Look at these file types -> *.csproj You will get list of project referencing this assembly.
Open all those project files in notepad and find out which one has different assembly signature than Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Most probably you should get culprit with above steps.
I will also recommend to check assembly cache and check signature of Microsoft.Practices.EnterpriseLibrary.Validation assembly and if it matches Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

Ninject ASP.NET extension throwing TypeLoadException

I'm trying to use Ninject 3 in an ASP.NET webforms application. We've been using it without the Ninject.Web extension for a while by creating a new injection kernel everywhere we needed one. It didn't occur to me until now that that's not the right way to do things. I wrote a little test application that is successfully using Ninject.Web, but when I tried to do the same thing in our real application, I'm receiving a TypeLoadException as soon as the page loads. It doesn't even make it into my code where I can set a breakpoint. Here's the exception and stack trace:
Could not load type
'System.Runtime.CompilerServices.ExtensionAttribute' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type
'System.Runtime.CompilerServices.ExtensionAttribute' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[TypeLoadException: Could not load type
'System.Runtime.CompilerServices.ExtensionAttribute' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'.]
System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken,
IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs,
Int32 methodInstCount, ObjectHandleOnStack type) +0
System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module,
Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext,
RuntimeTypeHandle[] methodInstantiationContext) +525
System.ModuleHandle.ResolveTypeHandle(Int32 typeToken,
RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[]
methodInstantiationContext) +19
System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,
Type[] genericTypeArguments, Type[] genericMethodArguments) +315
System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord
caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly,
RuntimeModule decoratedModule, MetadataToken decoratedToken,
RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[]
attributes, IList derivedAttributes, RuntimeType& attributeType,
IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean&
isVarArg) +208
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount,
RuntimeType attributeFilterType, Boolean mustBeInheritable, IList
derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1171
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly
assembly, RuntimeType caType) +146
WebActivator.AssemblyExtensions.GetActivationAttributes(Assembly
assembly) +114
WebActivator.ActivationManager.RunActivationMethods() +286
WebActivator.ActivationManager.RunPreStartMethods() +38
WebActivator.ActivationManager.Run() +56
[InvalidOperationException: The pre-application start initialization
method Run on type WebActivator.ActivationManager threw an exception
with the following error message: Could not load type
'System.Runtime.CompilerServices.ExtensionAttribute' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'..]
System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1
methods) +11567502
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +465
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager
appManager, IApplicationHost appHost, IConfigMapPathFactory
configMapPathFactory, HostingEnvironmentParameters hostingParameters,
PolicyLevel policyLevel, Exception appDomainCreationException) +1167
[HttpException (0x80004005): The pre-application start initialization
method Run on type WebActivator.ActivationManager threw an exception
with the following error message: Could not load type
'System.Runtime.CompilerServices.ExtensionAttribute' from assembly
'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089'..]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11556592
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
+141 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
wr, HttpContext context) +4813333
None of my searching has turned up anything terribly helpful, but the main avenue I've explored is a potential conflict between the version of .NET that Ninject was built against and the version that I'm actually running. I've never installed .NET 4.5 on my system, so I'm certain that I'm building against 4.0. I then built the most recent version of Ninject (3.0.2) and the extensions from source to be sure that it's using 4.0 as well. I also tried adding all the libraries that I'm using in the real app to my test app to see if there's a conflict but that didn't turn up anything. (However, I didn't go so far as to put in code that exercises them. I don't know if that would change anything.)
Has anyone seen this kind of problem before or have any ideas that I can try? Is there more info I can provide that would be helpful?
Alternatively, is there some other way I can use Ninject in an ASP.NET application instead of the ninject.web extension? Would wrapping the Ninject kernel up in a singleton work just as well?

Problem with ASP.NET AJAX Tabs

I get the following error intermitantly from the live website I develop (say twice a month).
From the stack trace, it seems to be internal to the AJAX control toolkit.
Error Message: Invalid object passed in, member name expected. (1): {"ActiveTabIndex":0,"TabState":[true,true,true,true]}
I have found once other person who has got the exact same error http://objectmix.com/software-testing/356582-microsoft-visual-studio-team-edition-software-tester-web-test.html
Its not a big issue but I'm interested to know what is causing it. Detailed stack trace is
Error Message: Invalid object passed in, member name expected. (1): {"ActiveTabIndex":0,"TabState":[true,true,true,true]}
Stack Trace: at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)
at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
at System.Web.Script.Serialization.JavaScriptSerializer.DeserializeObject(String input)
at AjaxControlToolkit.TabContainer.LoadClientState(String clientState) in C:\Program Files\Microsoft ASP.NET\AJAX Control Toolkit 3.0\AjaxControlToolkit\Tabs\TabContainer.cs:line 346
at AjaxControlToolkit.ScriptControlBase.LoadPostData(String postDataKey, NameValueCollection postCollection) in C:\Program Files\Microsoft ASP.NET\AJAX Control Toolkit 3.0\AjaxControlToolkit\ExtenderBase\ScriptControlBase.cs:line 314
at AjaxControlToolkit.TabContainer.LoadPostData(String postDataKey, NameValueCollection postCollection) in C:\Program Files\Microsoft ASP.NET\AJAX Control Toolkit 3.0\AjaxControlToolkit\Tabs\TabContainer.cs:line 447
at AjaxControlToolkit.ScriptControlBase.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) in C:\Program Files\Microsoft ASP.NET\AJAX Control Toolkit 3.0\AjaxControlToolkit\ExtenderBase\ScriptControlBase.cs:line 425
at System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

System.Drawing: GDI+ is not properly initialized (​internal GDI+ error​)

An ASP.NET Web Site raises randomly this System.Drawing-error:
System.Runtime.InteropServices.ExternalException: System.Drawing.Bitmap..ctor(Stream stream)
System.Drawing.ToolboxBitmapAttribute..cctor()
Exception information:
Exception type: TypeInitializationException
Exception message: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception.
Stack trace: at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.TypeDescriptor.GetAttributes(Type componentType)
at System.Web.UI.ThemeableAttribute.IsTypeThemeable(Type type)
at System.Web.UI.Control.ApplySkin(Page page)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Why? I think that this is a .NET Framework error (I'm actually not trying to create any images).
I found a temporary solution: restart IIS and delete Temporary ASP.NET Files ("%WINDIR%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files").
But when this error happens in the production web-server, temporary is not enough...
By coincidence we've had this on one of our servers today. It's a known issue in ASP.NET, there's a hotfix for it at http://support.microsoft.com/kb/975410.
Changing this setting to true in the web.config fixed it for me:
<validation validateIntegratedModeConfiguration="true" />

Resources