C# 企业库 CacheFactory.GetCacheManager 抛出 Null Ref

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 17:24:16  来源:igfitidea点击:

Enterprise Library CacheFactory.GetCacheManager Throws Null Ref

提问by Brian Sullivan

I'm trying to convert an application using the 1.1 version of the Enterprise Library Caching block over to the 2.0 version. I think where I'm really having a problem is that the configuration for the different EntLib pieces was split out over several files. Apparently, this used to be handled by the ConfigurationManagerSectionHandler, but is now obsolete in favor of the built-in configuration mechanisms in .NET 2.0.

我正在尝试将使用 1.1 版企业库缓存块的应用程序转换为 2.0 版。我认为我真正遇到的问题是不同 EntLib 部分的配置被拆分到几个文件中。显然,这曾经是由ConfigurationManagerSectionHandler处理的,但现在已经过时了,取而代之的是 .NET 2.0 中的内置配置机制。

I'm having a hard time finding a good example of how to do this configuration file splitting, especially in the context of EntLib. Has anyone else dealt with this?

我很难找到一个很好的示例来说明如何进行此配置文件拆分,尤其是在 EntLib 的上下文中。有没有其他人处理过这个问题?

采纳答案by Brian Sullivan

Looks like it was the configuration. I found a good example of the normal, one-file approach here: http://www.devx.com/dotnet/Article/31158/0/page/2

好像是配置。我在这里找到了一个正常的单文件方法的好例子:http: //www.devx.com/dotnet/Article/31158/0/page/2

Using an external config file is actually trivial once you figure out the syntax for it. Ex.:

一旦你弄清楚了它的语法,使用外部配置文件实际上是微不足道的。前任。:

In Web.config:

在 Web.config 中:

<cachingConfiguration configSource="cachingconfiguration.config" />

In cachingconfiguration.config:

在 cachingconfiguration.config 中:

<?xml version="1.0" encoding="utf-8"?>
<cachingConfiguration defaultCacheManager="Default Cache Manager">
    <backingStores>
        <add name="inMemory" type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching" />
    </backingStores>
    <cacheManagers>
        <add name="Default Cache Manager" expirationPollFrequencyInSeconds = "60" maximumElementsInCacheBeforeScavenging ="50" numberToRemoveWhenScavenging="10" backingStoreName="inMemory" />
    </cacheManagers>
</cachingConfiguration>

Hopefully this helps somebody!

希望这对某人有所帮助!