I want to use EnterpriseLibrary 5.0 dlls for logging in my project.
For this I have added these dll to my references:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Logging.Database
And then I write this:
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging;
And then I wrote:
LogEntry logEntry = new LogEntry();
logEntry.Message = "Message";
Logger.Write(logEntry);
But when my code executed, I get this exception at the last line:
Activation error occured while trying to get instance of type
LogWriter, key ""
that has this InnerException:
Resolution of the dependency failed, type =
\"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter\", name =
\"(none)\".\r\nException occurred while: Calling constructor
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String
fileName, System.String header, System.String footer,
Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter
formatter).\r\nException is: IOException - The device is not
ready.\r\n\r\n-----------------------------------------------\r\nAt
the time of the exception, the container was:\r\n\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl,LogWriter.default
(mapped from Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,
(none))\r\n Resolving parameter \"structureHolder\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterImpl(Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder
structureHolder,
Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider
instrumentationProvider,
Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator
updateCoordinator)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,LogWriterStructureHolder.default
(mapped from
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder,
(none))\r\n Resolving parameter \"traceSources\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriterStructureHolder(System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.Filters.ILogFilter,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35]] filters,
System.Collections.Generic.IEnumerable1[[System.String, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
traceSourceNames,
System.Collections.Generic.IEnumerable1[[Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35]] traceSources,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
allEventsTraceSource,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
notProcessedTraceSource,
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource
errorsTraceSource, System.String defaultCategory, System.Boolean
tracingEnabled, System.Boolean logWarningsWhenNoCategoriesMatch,
System.Boolean revertImpersonation)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource,Trace\r\n
Resolving parameter \"traceListeners\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.LogSource(System.String
name,
System.Collections.Generic.IEnumerable1[[System.Diagnostics.TraceListener,
System, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]] traceListeners,
System.Diagnostics.SourceLevels level, System.Boolean autoFlush,
Microsoft.Practices.EnterpriseLibrary.Logging.Instrumentation.ILoggingInstrumentationProvider
instrumentationProvider)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper,Flat
FileTrace Listener (mapped from System.Diagnostics.TraceListener, Flat
FileTrace Listener)\r\n Resolving parameter
\"wrappedTraceListener\" of constructor
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.ReconfigurableTraceListenerWrapper(System.Diagnostics.TraceListener
wrappedTraceListener,
Microsoft.Practices.EnterpriseLibrary.Logging.ILoggingUpdateCoordinator
coordinator)\r\n Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,Flat
FileTrace Listener‌implementation (mapped from
System.Diagnostics.TraceListener, Flat FileTrace
Listener‌implementation)\r\n Calling constructor
Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener(System.String
fileName, System.String header, System.String footer,
Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter
formatter)
And it has this InnerException:
The device is not ready.
How to I can resolve this error?
Read the following article: How to configure and use Microsoft Enterprise Library 5 for logging
This error was from app.config file.
I'd use a same app.config file that has some error.
When I used an app.config that creates with EntLib application, My error resolved.
Related
I am trying to sort out a friends service. Basically it gets into error as soon as I start it in constructor. Here are the code fragments.
public class DefaultCacheManager : ICacheManager
{
private readonly Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager _cacheManager;
public DefaultCacheManager()
{
//Code blows here
_cacheManager = CacheFactory.GetCacheManager();
}
The error I get is below.
Unhandled Exception: System.TypeInitializationException: The type initializer for 'Test.TypeManagement' threw an exception. --->
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the
dependency failed, type = "Test.DefaultCacheManager", name
="CacheManager".Exception occurred while: Calling constructor Test.DefaultCacheManager(). Exception is: TypeLoadException - Could
not load type
'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer'
from assembly 'Microsoft.Practices.EnterpriseLibrary.Common,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
----------------------------------------------- At the time of the exception, the container was:
Resolving Test.DefaultCacheManager,CacheManager Calling
constructor Test.DefaultCacheManager() ---> System.TypeLoadException:
Could not load type
'Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer'
from assembly 'Microsoft.Practices.EnterpriseLibrary.Common,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
at
Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.InnerGetCacheManager(String
cacheManagerName) at Test.DefaultCacheManager..ctor() in
c:\Test\CacheManager.cs:line 12 at lambda_method(Closure ,
IBuilderContext ) at
Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.b__0(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext
context) at
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext
context) at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type
t, Object existing, String name, IEnumerable1 resolverOverrides)
--- End of inner exception stack trace --- at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object
existing, String name, IEnumerable1 resolverOverrides) at
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String
name, IEnumerable`1 resolverOverrides) at
Microsoft.Practices.Unity.UnityContainerExtensions.Resolve[T](IUnityContainer
container, String name, ResolverOverride[] overrides) at
Test.TypeManagement.get_CacheManager() in
c:\Test\TypeManagement.cs:line 56 at Test.TypeManagement..cctor()
in c:\Test\TypeManagement.cs:line 36 --- End of inner exception
stack trace --- at Test.TypeManagement.get_ServiceHost() at
Test.ThreadManager.Start() in c:\Test\ThreadManager.cs:line 19 at
Test.Program.Main(String[] args) in c:\Test\Program.cs:line 14
Any help and direction would be most welcomed.
Config
<configSections>
<section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<cachingConfiguration defaultCacheManager="Cache Manager">
<cacheManagers>
<add expirationPollFrequencyInSeconds="60" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="Data Cache Storage" name="Cache Manager" />
</cacheManagers>
<backingStores>
<add databaseInstanceName="CachingStaging" partitionName="CS" encryptionProviderName="" type="Microsoft.Practices.EnterpriseLibrary.Caching.Database.DataBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching.Database, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" name="Data Cache Storage" />
</backingStores>
</cachingConfiguration>
I've created a very basic Logging block and Exception Handling block. In my code, I went to go test the Exception Handling (I know the Logging block works) with the following:
public void RunScriptClean()
{
try
{
throw new FileNotFoundException();
}
catch (FileNotFoundException ex)
{
var b = ExceptionPolicy.HandleException(ex, "Logging Policy");
if (b)
throw;
}
}
However, on the very first line of the catch block, I get this long winded exception and my application crashes:
Exception occured: The current build operating (build key Build Key [Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Logging Policy]) failed: The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' cannot be resolved. Please verify the spelling is correct or that the full type name is provided. (Strategy type ConfiguredObjectStrategy, index 2).
I have absolutely no idea what it's referring to when it says the type cannot be resolved. I've added references to Microsoft.Practices.EnterpriseLibrary.Common/ExceptionHandling/Logging and Ms.Practices.ObjectBuilder2. This one class has using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling included at the top.
Added a screenshot of the configuration tool looking at my AppConfig file:
I'm sure I'm missing something basic, but it's tough to find a tutorial for EAB 4.1-- CodeProject has a lot for the original versions but I couldn't make much of them...
Edit I tried creating a new Formatter and naming it TextExceptionFormatter but that didn't change anything. Wasn't sure if maybe some how the FormatterType property on my Logging Handler was tied to that node.
And the actual block of XML from App.config:
<exceptionHandling>
<exceptionPolicies>
<add name="Logging Policy">
<exceptionTypes>
<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="Exception">
<exceptionHandlers>
<add logCategory="General" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="Logging Handler" />
</exceptionHandlers>
</add>
</exceptionTypes>
</add>
</exceptionPolicies>
</exceptionHandling>
I found this SO question: Cannot resolve type runtime error after registering the Enterprise Library into the GAC but even after changing the Version segment of the fullName attribute my app still behaves the same.
Alright, I was able to find a sample application that used the Logging handlers. Turns out I needed a reference to ExceptionHandling.Logging:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging ****
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.ObjectBuilder2
Where as I only had a references to:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.ObjectBuilder2
Alright so this is what I have
private static AppDomain CreateSandbox()
{
var permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
permissions.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read| FileIOPermissionAccess.PathDiscovery, AppDomain.CurrentDomain.BaseDirectory));
var appinfo = new AppDomainSetup();
appinfo.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
return AppDomain.CreateDomain("Scripting sandbox", null, appinfo, permissions, fullTrustAssembly);
}
And when I try to load up some broken python code
try
{
var src = engine.CreateScriptSourceFromString(s.Python, SourceCodeKind.Statements);
src.Execute(ActionsScope);
}
catch (Exception e)
{
ExceptionOperations eo = engine.GetService<ExceptionOperations>();
string error = eo.FormatException(e);
Debug.WriteLine(error);
}
This gives me a SecurityException instead of letting me see the actual exception from the code.
If I set the PermissionSet(PermissionState.Unrestricted) it works fine.
Any ideas on what permissions I need in order to catch these blasted errors?
System.Security.SecurityException was caught
Message=Request failed.
Source=Microsoft.Scripting
GrantedSet=<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="F:\Programming\OCTGN\octgnFX\Octgn\bin\ReleaseMode with Debug\"
PathDiscovery="F:\Programming\OCTGN\octgnFX\Octgn\bin\ReleaseMode with Debug\"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
</PermissionSet>
PermissionState=<PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>
RefusedSet=""
Url=file:///F:/Programming/OCTGN/octgnFX/Octgn/bin/ReleaseMode with Debug/Microsoft.Scripting.DLL
StackTrace:
at Microsoft.Scripting.SyntaxErrorException.GetObjectData(SerializationInfo info, StreamingContext context)
at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at Octgn.Scripting.Engine.LoadScripts() in F:\Programming\OCTGN\octgnFX\Octgn\Scripting\Engine.cs:line 58
InnerException:
Based on the stack trace, you have a syntax error in your code, so the Python runtime throws SyntaxErrorException. That exception is not caught and so it has to be serialized across the appdomain boundary.
I think the problem now is that the method GetObjectData() of SyntaxErrorException is marked [SecurityCritical], which means it can be called only by fully trusted code.
You might want to try the ObjectHandle ExecuteAndWrap(ScriptScope scope, out ObjectHandle exception) overload. When you're just catching the exception it gets marshaled from the remote domain to your domain when it's thrown, and then back to the remote domain when you call FormatException. It looks like the exception is happening on the marshaling back to your app domain.
If you call the ExecuteAndWrap overload then you'll just get handles to the result and possible exception and avoid the serialization - you can then pass the handle back ExceptionOperations.FormatException.
I seem to have hit a wall here and would appreciate some help from anyone who is able to on this one. I am not exactly sure what the error message below means. I am using the Caching Block of Enterprise Pattern Services but I keep running in to the problem below. I downloaded the latest version and tried stepping through to the issue but I can't seem to pin the exact problem and I need help please. Thanks in advance
Test method WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call_Children_out_of_schoolTest threw exception:
Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type ICacheManager, key "Cache Manager" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager", name = "Cache Manager".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager,WuCache
---> System.InvalidOperationException: The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface and cannot be constructed. Are you missing a type mapping?
Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.ThrowForAttemptingToConstructInterface(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs: line 209
BuildUp_Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager(IBuilderContext )
Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlan.cs: line 37
Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs: line 43
Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs: line 110
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs: line 511
Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs: line 515
Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs: line 173
Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityServiceLocator.cs: line 64
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs: line 49
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs: line 53
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs: line 103
Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.InnerGetCacheManager(String cacheManagerName) in e:\Builds\EntLib\Latest\Source\Blocks\Caching\Src\Caching\CacheFactory.cs: line 66
Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager(String cacheManagerName) in e:\Builds\EntLib\Latest\Source\Blocks\Caching\Src\Caching\CacheFactory.cs: line 53
WorldBank.Service.Business.ResponseManager.Get_w_Utility() in C:\SOOfficialPiece\WorldBank.Service.Business\ResponseManager.cs: line 42
WorldBank.Service.Business.ResponseManager..ctor() in C:\SOOfficialPiece\WorldBank.Service.Business\ResponseManager.cs: line 34
WorldBank.Service.Business.ResponseManager.getResponseObjectJSON(Int32 perpage, Object results, Boolean doDeepRetrieval) in C:\SOOfficialPiece\WorldBank.Service.Business\ResponseManager.cs: line 68
System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
WorldBankBusiness.Topics.TopicsManager.Call_Children_out_of_school(PersonType persontype, EnrollmentType enrollmenttype, String countrycode) in C:\SOOfficialPiece\WorldBank.Service.Business\TopicsManager.cs: line 39
WorldBank.Service.Business.UnitTest.TopicsManagerTest.Call_Children_out_of_schoolTest() in C:\SOOfficialPiece\WorldBank.Service.Business.UnitTest\TopicsManagerTest.cs: line 88
The Caching Application Block requires some configuration information to be present in the app/web.config before it can be used (AFAIK, unfortunately it is tough to find documentation stating otherwise). Without that configuration info, the following code will cause that same exception to be thrown as you are seeing:
var cm = CacheFactory.GetCacheManager("MyCacheManager");
In order to get a CacheManager, you need to define the CacheManager in your app.config or web.config:
<configuration>
<configSections>
<section name="cachingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<cachingConfiguration defaultCacheManager="MyCacheManager">
<cacheManagers>
<add name="MyCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="50000"
numberToRemoveWhenScavenging="1000"
backingStoreName="NullBackingStore" />
</cacheManagers>
<backingStores>
<add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="NullBackingStore" />
</backingStores>
</cachingConfiguration>
</configuration>
Once you add the configuration values, you should be able to get a valid CacheManager from the CacheFactory. The post also has some more information that might help you.
It is worth noting that if you are using .NET 4.0, for non web apps you can use MemoryCache (in the System.Runtime.Caching namespace) which provides similar functionality but does not require all of this configuration. And for web apps you can of course use the Cache class in System.Web.Caching.
We have a simple task that, before compiling, makes all of our AssemblyInfo.cs files editable, then updates
[assembly: AssemblyVersion("1.0.0.0")]
to
[assembly: AssemblyVersion("1.0.0.<SourceGetVersion>")]
All of our assemblies are signed using the same key.
This kind of thing is probably fairly standard, and it works just fine, except that it causes test failures.
The failures look like this:
Test method
Namespace.Tests.MessageTest.TestMethod
threw exception:
System.IO.FileLoadException: Could not
load file or assembly
'Namespace.BusinessLayer.BusinessComponent.Documents,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
So, I turned on the logging that was suggested, and get this:
W, 3964, 90, 2010/12/07, 09:57:43.059,
TFSBUILD\QTAgent32.exe, Getting
custom attributes for type
System.Reflection.RuntimeMethodInfo
threw exception (will ignore and use
the reflection way):
System.IO.FileLoadException: Could not
load file or assembly
'Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
File name:
'Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx' at
System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule
pModule, IRuntimeMethodInfo pCtor,
Byte** ppBlob, Byte* pEndBlob, Int32*
pcNamedArgs) at
System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule
module, IRuntimeMethodInfo ctor,
IntPtr& blob, IntPtr blobEnd, Int32&
namedArgs) at
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule
decoratedModule, Int32
decoratedMetadataToken, Int32
pcaCount, RuntimeType
attributeFilterType, Boolean
mustBeInheritable, IList
derivedAttributes, Boolean
isDecoratedTargetSecurityTransparent)
at
System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo
method, RuntimeType caType, Boolean
inherit) at
System.Reflection.RuntimeMethodInfo.GetCustomAttributes(Boolean
inherit) at
Microsoft.VisualStudio.TestTools.Common.ReflectHelper.GetAttributes(MemberInfo
info, Boolean bInherit)
=== Pre-bind state information === LOG: User = domain\tfsbuildAccount
LOG: DisplayName =
Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx
(Fully-specified) LOG: Appbase =
file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD
2010-12-07 09_56_54_x86_Debug/Out LOG:
Initial PrivatePath = NULL Calling
assembly :
Namespace.BusinessLayer.BusinessComponent.Edi.Tests,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx.
=== LOG: This bind starts in default load context. LOG: Using application
configuration file:
D:\Builds\4\10\TestResults\tfsbuildAccount-TFSBUILD
2010-12-07
09_56_54_x86_Debug\Out\Namespace.BusinessLayer.BusinessComponent.Edi.Tests.DLL.config
LOG: Using host configuration file:
LOG: Using machine configuration file
from
C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference:
Namespace.BusinessLayer.BusinessEntity,
Version=1.0.0.4344, Culture=neutral,
PublicKeyToken=xxxxxxxxxxxxxxxx LOG:
Attempting download of new URL
file:///D:/Builds/4/10/TestResults/tfsbuildAccount-TFSBUILD
2010-12-07
09_56_54_x86_Debug/Out/Namespace.BusinessLayer.BusinessEntity.DLL.
WRN: Comparing the assembly name
resulted in the mismatch: Revision
Number ERR: Failed to complete setup
of assembly (hr = 0x80131040). Probing
terminated.
Now, I may have mixed up the assemblies posting this, but it's the same pattern for all the tests. Mind you, the public keys are all the same, and I can see that all of the revision numbers are the same.
What are we doing wrong?
Try changing the reference assebly to be not version specific. "Secific Version = False" in the properties tab for the assembly.