Possible Install Problem?

Topics: Cryptography Application Block
May 28, 2008 at 4:10 AM
I am practicing encryption and decryption using EL 4.0. I used new install of VS2008 with only EL4.0 installed. The crypto quick start works fine for me; I think it is because the source code is included within the quick start. The Jan2006 hands on labs are for previous version and does not really provide a good source of reference.
My problem is, I have not stopped getting the "Could not load or assembly... .Cryptography, Version 4.0.0.0,...". I added a new reference to the project, I double checked the code (C#) and nothing tells me what went wrong. The problem does not seem to be related to the code but the installation and I am in a lost. I would appreciate any one who can give a hint or 2 in what I shold be checking to get the problem resolved.
May 28, 2008 at 3:07 PM
Hi,

I'll assume your error is “An error occurred creating the configuration section handler for [section name]: Could not load file or assembly '[assembly name]' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”.

This error occurs when the configuration file references binaries with a given identity but the assemblies deployed with the application have a different identity. Most likely the configuration was created with the “Enterprise Library Configuration Editor” integrated in Visual Studio using the Microsoft-signed binaries but the application references the unsigned source code projects. In order to match the configuration authored with the IDE configuration editor with the actual assemblies referenced by the application and copied during the build process, a configuration set must be set for the solution. Two such sets are defined by default during install: one for the signed binaries and one for the unsigned sources.

If this is not the error, then precisely describe your problem and post the details of the exception you get, including the full error message (the public key makes a difference) and a stack trace.

Hope this helps.
Fernando


jawtang wrote:
I am practicing encryption and decryption using EL 4.0. I used new install of VS2008 with only EL4.0 installed. The crypto quick start works fine for me; I think it is because the source code is included within the quick start. The Jan2006 hands on labs are for previous version and does not really provide a good source of reference.
My problem is, I have not stopped getting the "Could not load or assembly... .Cryptography, Version 4.0.0.0,...". I added a new reference to the project, I double checked the code (C#) and nothing tells me what went wrong. The problem does not seem to be related to the code but the installation and I am in a lost. I would appreciate any one who can give a hint or 2 in what I shold be checking to get the problem resolved.



May 28, 2008 at 3:35 PM
Thanks for the quick response. This is the message I got,
"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."
I actually was getting the message you mentioned if I included common.dll in the reference. After removing common.dll from the reference I ended up with the above error message.  Below is a copy from what VS was telling me.
Thanks.

System.IO.FileNotFoundException was unhandled
  Message="Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."
  Source="Cryptkeeper"
  FileName="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  FusionLog="=== Pre-bind state information ===\r\nLOG: User = [...]\r\nLOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\n (Fully-specified)\r\nLOG: Appbase = file:///D:/Visual Studio/Cryptkeeper/Cryptkeeper/bin/Release/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : Cryptkeeper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: No application configuration file found.\r\nLOG: Using machine configuration file from C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.\r\nLOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\nLOG: The same bind was seen before, and was failed with hr = 0x80070002.\r\n"
  StackTrace:
       at Cryptkeeper.Main.button1_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Cryptkeeper.Program.Main() in D:\Visual Studio\Cryptkeeper\Cryptkeeper\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
May 28, 2008 at 4:07 PM
Hi,

Use the Fusion Log Viewer to determine the cause for the failure load. You do need the Common assembly though; it seems to me you're mixing source and binary references here.

Fernando


jawtang wrote:
Thanks for the quick response. This is the message I got,
"Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."
I actually was getting the message you mentioned if I included common.dll in the reference. After removing common.dll from the reference I ended up with the above error message.  Below is a copy from what VS was telling me.
Thanks.

System.IO.FileNotFoundException was unhandled
  Message="Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."
  Source="Cryptkeeper"
  FileName="Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  FusionLog="=== Pre-bind state information ===\r\nLOG: User = [...]\r\nLOG: DisplayName = Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\n (Fully-specified)\r\nLOG: Appbase = file:///D:/Visual Studio/Cryptkeeper/Cryptkeeper/bin/Release/\r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : Cryptkeeper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.\r\n===\r\nLOG: This bind starts in default load context.\r\nLOG: No application configuration file found.\r\nLOG: Using machine configuration file from C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\config\\machine.config.\r\nLOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\nLOG: The same bind was seen before, and was failed with hr = 0x80070002.\r\n"
  StackTrace:
       at Cryptkeeper.Main.button1_Click(Object sender, EventArgs e)
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Cryptkeeper.Program.Main() in D:\Visual Studio\Cryptkeeper\Cryptkeeper\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:



May 29, 2008 at 9:35 PM
Thanks for your help and it took me a wile to get fuslogvw.exe going. Below if what I got from the viewer,
It looks like it failed not able to find the Cryptography.DLL base on the machine.config; how can I correct this?

===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Visual Studio\Crypto\Crypto\bin\Debug\Crypto.vshost.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Visual Studio/Crypto/Crypto/bin/Debug/Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\Visual Studio\Crypto\Crypto\bin\Debug\Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

May 30, 2008 at 7:13 PM
As I mentioned previously, you're mixing the assemblies' identities. Config asks for the signed version but it's the unsigned version that is available in your app's folder. Please refere to my previous answer for instructions on how to deal with this.

Fernando

jawtang wrote:
Thanks for your help and it took me a wile to get fuslogvw.exe going. Below if what I got from the viewer,
It looks like it failed not able to find the Cryptography.DLL base on the machine.config; how can I correct this?

===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\Visual Studio\Crypto\Crypto\bin\Debug\Crypto.vshost.exe.Config
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///D:/Visual Studio/Crypto/Crypto/bin/Debug/Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.DLL.
LOG: Assembly download was successful. Attempting setup of file: D:\Visual Studio\Crypto\Crypto\bin\Debug\Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Microsoft.Practices.EnterpriseLibrary.Security.Cryptography, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null
WRN: Comparing the assembly name resulted in the mismatch: PUBLIC KEY TOKEN
ERR: The assembly reference did not match the assembly definition found.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.




May 31, 2008 at 3:13 AM
Thanks fsimonazzi for smacking me on the head, without that I will never find what went wrong. What I did wrong was that I added references from the folder C:\EntLib4Src\bin where the installer put the source code at. Instead, I should have used those references from C:\Program Files\Microsoft Enterprise Library 4.0 - May 2008\Bin. Thanks one more time for your help.