File Load Exception on Microsoft.Practices.EnterpriseLibrary.Common

Topics: Logging Application Block
Jun 27, 2008 at 10:20 PM
Im trying to use Logging application block in my app and I get the following error when trying to create a log entry object. I am using the DatAccess block as well and it works without any issues in the same project so I don't think its a reference issue.

Error    1    TestCase 'SampleGenerator.NUnit.SampleGeneratorTest.TestSample'
failed: System.TypeInitializationException : The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry' threw an exception.
  ----> System.IO.FileLoadException : Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry..ctor()
 .......
......
--FileLoadException
   at System.ModuleHandle.ResolveMethod(Int32 methodToken, RuntimeTypeHandle* typeInstArgs, Int32 typeInstCount, RuntimeTypeHandle* methodInstArgs, Int32 methodInstCount)
   at System.ModuleHandle.ResolveMethodHandle(Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.ModuleHandle.ResolveMethodHandle(Int32 methodToken)
   at System.RuntimeType.GetMethodBase(ModuleHandle scope, Int32 typeMetadataToken)
   at System.RuntimeType.GetMethodBase(Module scope, Int32 typeMetadataToken)
   at System.Reflection.CustomAttributeData..ctor(Module scope, CustomAttributeRecord caRecord)
   at System.Reflection.CustomAttributeData.GetCustomAttributes(Module module, Int32 tkTarget)
   at System.Reflection.CustomAttributeData.GetCustomAttributes(Assembly target)
   at System.Resources.ResourceManager.GetNeutralResourcesLanguage(Assembly a, UltimateResourceFallbackLocation& fallbackLocation)
   at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
   at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
   at Microsoft.Practices.EnterpriseLibrary.Logging.Properties.Resources.get_DefaultTextFormat()
   at Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter..ctor()
   at Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry..cctor()   
Jun 30, 2008 at 3:19 PM
Looks like you have version conflict of the Dlls. Please refer the proper DLL's OR  remove the version attributes in the config file and run.
Jun 30, 2008 at 4:30 PM
Hi,

As APeter mentions there's a conflict between the configuration file and the dlls. Most likely you've referenced the source code projects but have configuration for the signed binaries, which is typically the case when you're using the VS Configuration Tool without setting the configuration set. If that's the case, you would find this post from Tom Hollander helpful.

Fernando
Jun 30, 2008 at 9:50 PM
Thanks guys, That was the problem, I had one dll from the compiled source code and another from pre-complied libraries. Once I got everything from one place it worked fine.
Nov 4, 2008 at 4:26 PM
i had the similar issue and the reason was that my .net config files were messed up. I had to reset machine.config and security.config.

Then it all worked.
Feb 12, 2009 at 11:58 PM
I am having a somewhat similar issue however I don't believe it is a dll conflict.

I am getting the Type Initializer exception, however the inner exception is that it can't load System.Core but the 3.5 version of it.  The app is a winforms .NET 2.0 app and has no references to any 3.5 dlls. 

The one oddball thing is that we are using the Logging and Common from EntLib 3.1 but we are using Unity from EntLib 4.0. 

Any thoughts on why my app suddenly wants .NET 3.5 runtime installed when I add references to the EntLib 3.1 Logging and Common dlls?

Feb 13, 2009 at 8:54 AM
Edited Feb 13, 2009 at 9:10 AM
Hi,

Can you provide the Exception details? Do you have other version of Entlib installed on the same machine ? Also, as the previous post says, try to reset your machine.config.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 13, 2009 at 3:38 PM
System.TypeInitializerException
The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry' threw an exception

(inner exception)
System.Io.FileNotFoundException
Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

This is a winforms app, not a web app so the machine I get the error on is a clean XP install without .NET 3.5 or Enterprise Library.   All of our development machines have both EntLib 3.1 and EntLib 4.0 installed but everything works fine on the dev machines.  It is only on a clean machine with a fresh install that this problem comes up.

I know that the .dlls for Logging and Common from EntLib 3.1 are being installed on the machine.  I also know that the Unity and ObjectBuilder2 .dlls are being installed as well.  The application is compiled for .NET 2.0 and until I added the Logging app block yesterday we never had any exceptions referring to 3.5.  We have been using the Unity and ObjectBuilder2 .dlls since they came out and have never had any 3.5 errors with them. 

The frustrating thing is that the bug that I need the logging for only occurs on "clean" installs as well!  I am certain it is unrelated to any of these issues however as it is a timezone conversion issue. 

Thanks for any thoughts you can provide.
Feb 14, 2009 at 6:35 AM
What version of entlib assemblies are you actually using?  The 3.1 or the 4.0?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Aug 31, 2009 at 8:07 PM

Hi, for over a year now, we have had a similar issue to that of what was described above.  The exception below is thrown when we attempt to write to our logging database.  The issue, however, is that for days\weeks at a time we do not have an issue, and it is only periodic that we receive the issue below.  We are using the logging block within an ASP.NET app, and once we bounce the IIS application pool, the issue disappears.  It is impossible to find a resolution to this issue on the web, any help would be greatly appreciated.

Error Message:
The following error was captured while attempting to write to the logging database: System.TypeInitializationException: The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Access is denied. File name: 'Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral...

Sep 1, 2009 at 4:41 AM

Will it be possible for you to catch the bind logging information by turning on fusion logs? - http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx.  After getting the exception you posted above, check the corresponding log for the Common assembly and you'll see where is it trying to load that assembly. 

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 1, 2009 at 1:26 PM

Thanks so much Sarah, we'll most certainly give this a shot, I'll let you know how it turns out.

Dec 9, 2009 at 10:27 AM

Hey ewitkows,

Did you have any luck with this? We're experiencing a similar message although we are only using the data access part of Enterprise Library.

Thanks

Feb 2, 2010 at 11:10 PM
MSwaffer wrote:
I am having a somewhat similar issue however I don't believe it is a dll conflict.

I am getting the Type Initializer exception, however the inner exception is that it can't load System.Core but the 3.5 version of it.  The app is a winforms .NET 2.0 app and has no references to any 3.5 dlls. 

The one oddball thing is that we are using the Logging and Common from EntLib 3.1 but we are using Unity from EntLib 4.0. 

Any thoughts on why my app suddenly wants .NET 3.5 runtime installed when I add references to the EntLib 3.1 Logging and Common dlls?

 

Hi, i have exactly the same issue, the system can't load the 3.5 version of the core dll, meanwhile the project was compiled with target .net 2.0

this is a clean xp machine, with .net 2.0 installed, the project was compiled with VS2008 (another machine) with .net 2.0 target , using Entlib 4.1

if i compile it with vs2005 then everything is fine.

here's the fusion log:

 

*** Assembly Binder Log Entry  (2010. 02. 02. @ 23:55:33) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  c:\a\szmini.winapp.exe
--- A detailed error log follows.

=== Pre-bind state information ===
LOG: User = VMXPENGSP2\Administrator
LOG: DisplayName = System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///c:/a/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\a\szmini.winapp.exe.Config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///c:/a/System.Core.DLL.
LOG: Attempting download of new URL file:///c:/a/System.Core/System.Core.DLL.
LOG: Attempting download of new URL file:///c:/a/System.Core.EXE.
LOG: Attempting download of new URL file:///c:/a/System.Core/System.Core.EXE.
LOG: All probing URLs attempted and failed.

 

Feb 3, 2010 at 1:49 AM

Do you have any entlib assemblies in GAC?

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 3, 2010 at 9:51 AM
AvanadeSupport wrote:

Do you have any entlib assemblies in GAC?

No, entlib is placed in the application folder.

Some information which i found:

i checked the Microsoft.Practices.EnterpriseLibrary.Common.dll with reflector, and it show the system.core 3.5.0.0 dependecy, but when i compile it with vs2005, then everything is fine, and .net 3.5 is not needed.

this solution has a setup project too, and the installer is not messaging about the missing .net 3.5 framework when deployed to the client machine, of course in the prereq. .net 2.0 is checked.

 

maybe i will install vs2005 to the client machine, and i will debug the entlib source, to find out where this refernce comes up

Feb 3, 2010 at 10:01 AM

Could you post the exact error message?  I'm not sure if you're getting the TypeInitializer exception for the LogEntry and the typeinitializer for .net 3.5 as the inner exception.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 3, 2010 at 10:05 AM

Here's my exception, but as you will notice, my problem is not related to the logging block, my problem comes up when i try to connect to a sql compact 3.5 sp1 database

 

 

(Inner Exception)
Date and Time:         2010. 02. 03. 10:12:49
Machine Name:          VMXPENGSP2
IP Address:            192.168.23.136
Current User:          VMXPENGSP2\Administrator

Application Domain:    szmini.winapp.exe
Assembly Codebase:     file:///C:/Program Files/MiniSzamlamester/szmini.winapp.exe
Assembly Full Name:    szmini.winapp, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null
Assembly Version:      1.4.1.0
Assembly Build Date:   2010. 02. 03. 10:05:26

Exception Source:      mscorlib
Exception Type:        System.IO.FileNotFoundException
Exception Message:     Could not load file or assembly 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
Exception Target Site: ResolveMethod

---- Stack Trace ----
   System.ModuleHandle.ResolveMethod(methodToken As Int32, typeInstArgs As RuntimeTypeHandle*, typeInstCount As Int32, methodInstArgs As RuntimeTypeHandle*, methodInstCount As Int32)
       szmini.winapp.exe: N 00000
   System.ModuleHandle.ResolveMethodHandle(methodToken As Int32, typeInstantiationContext As RuntimeTypeHandle[], methodInstantiationContext As RuntimeTypeHandle[])
       szmini.winapp.exe: N 00149
   System.Reflection.CustomAttributeData..ctor(scope As Module, caRecord As CustomAttributeRecord)
       szmini.winapp.exe: N 00091
   System.Reflection.CustomAttributeData.GetCustomAttributes(module As Module, tkTarget As Int32)
       szmini.winapp.exe: N 00082
   System.Reflection.CustomAttributeData.GetCustomAttributes(target As Assembly)
       szmini.winapp.exe: N 00056
   System.Resources.ResourceManager.GetNeutralResourcesLanguage(a As Assembly, fallbackLocation As UltimateResourceFallbackLocation&)
       szmini.winapp.exe: N 00043
   System.Resources.ResourceManager.InternalGetResourceSet(culture As CultureInfo, createIfNotExists As Boolean, tryParents As Boolean)
       szmini.winapp.exe: N 00185
   System.Resources.ResourceManager.GetString(name As String, culture As CultureInfo)
       szmini.winapp.exe: N 00074
   Microsoft.Practices.EnterpriseLibrary.Data.Properties.Resources.get_Password()
       szmini.winapp.exe: N 00027
   Microsoft.Practices.EnterpriseLibrary.Data.Database..cctor()
       szmini.winapp.exe: N 00041



(Outer Exception)
Date and Time:         2010. 02. 03. 10:12:50
Machine Name:          VMXPENGSP2
IP Address:            192.168.23.136
Current User:          VMXPENGSP2\Administrator

Application Domain:    szmini.winapp.exe
Assembly Codebase:     file:///C:/Program Files/MiniSzamlamester/szmini.winapp.exe
Assembly Full Name:    szmini.winapp, Version=1.4.1.0, Culture=neutral, PublicKeyToken=null
Assembly Version:      1.4.1.0
Assembly Build Date:   2010. 02. 03. 10:05:26

Exception Source:      Microsoft.Practices.EnterpriseLibrary.Data
Exception Type:        System.TypeInitializationException
Exception Message:     The type initializer for 'Microsoft.Practices.EnterpriseLibrary.Data.Database' threw an exception.
Exception Target Site: .ctor

---- Stack Trace ----
   Microsoft.Practices.EnterpriseLibrary.Data.Database..ctor(connectionString As String, dbProviderFactory As DbProviderFactory)
       szmini.winapp.exe: N 00000
   Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.SqlCeDatabase..ctor(connectionString As String)
       szmini.winapp.exe: N 00011
   szmini.Data.SqlCeClient.SqlCeSystemprefsProviderBase.GetByValuename(transactionManager As TransactionManager, _valuename As String, start As Int32, pageLength As Int32, count As Int32&)
       szmini.winapp.exe: N 00110
   szmini.Data.Bases.SystemprefsProviderBaseCore.GetByValuename(_valuename As String)
       szmini.winapp.exe: N 00070
   szmini.bll.mysystemprefs.IsValueExists(valuename As String)
       szmini.winapp.exe: N 00065
   szmini.bll.myapplication.Init()
       szmini.winapp.exe: N 00113
   szmini.winapp.mainmodule.Main()
       szmini.winapp.exe: N 00070

Feb 11, 2010 at 8:41 AM
Edited Feb 11, 2010 at 8:45 AM

I forgot to mention, sorry, but actually, EntLib 4.1 is not supported on .NET 2.0.  Although there is a possibility that it would work (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=64734). Just curious if you ever get this work.

Feb 11, 2010 at 9:12 AM
AvanadeSupport wrote:

I forgot to mention, sorry, but actually, EntLib 4.1 is not supported on .NET 2.0.  Although there is a possibility that it would work (http://entlib.codeplex.com/Thread/View.aspx?ThreadId=64734). Just curious if you ever get this work.

Hi,

ok , of course i know entlib4.1 is for 3.5 only, but you can believe me, i have a complete project (deployed to customers) with entlib 4.1, .net 2.0, with vs2005, and it has not any problem.

the problem comes up when i try to migrate it to vs2008, and the project stopped working with the above message.

Feb 11, 2010 at 9:56 AM

Does referencing some of the 3.1 version of the dlls an option for you like what was suggested here - http://entlib.codeplex.com/Thread/View.aspx?ThreadId=61598?  I really have no idea how come it's working in vs2005 and not in vs2008.