<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Localization</title><link>http://forums.asp.net/151.aspx</link><description>Discuss techniques for localizing content for different languages and locales with ASP.NET.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>System.ObjectDisposedException: Cannot access a closed resource set</title><link>http://forums.asp.net/thread/3271636.aspx</link><pubDate>Thu, 02 Jul 2009 14:53:52 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3271636</guid><dc:creator>jasscat</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3271636.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=151&amp;PostID=3271636</wfw:commentRss><description>&lt;p&gt;I have a local resource file in my application that I&amp;#39;m accessing using strongly typed properties created with the StronglyTypedResourceBuilder.&amp;nbsp; I access this resource file a couple of different ways.&lt;/p&gt;&lt;p&gt;At first, I&amp;#39;m creating a DataTable of resource keys/values like this (using the strongly typed Resource Manager property of the resource class) :&lt;/p&gt;&lt;pre style="font-size:12px;"&gt;&lt;font color="black"&gt;IDictionaryEnumerator _reader &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;resourceset.GetEnumerator&lt;/font&gt;&lt;font color="gray"&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;while &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;_reader.MoveNext&lt;/font&gt;&lt;font color="gray"&gt;())&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DataRow dr &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;dt.NewRow&lt;/font&gt;&lt;font color="gray"&gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dr[&amp;quot;Name&amp;quot;] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;_reader.Key as &lt;/font&gt;&lt;font color="blue"&gt;string&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dr[&amp;quot;Value&amp;quot;] &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;_reader.Value as &lt;/font&gt;&lt;font color="blue"&gt;string &lt;/font&gt;&lt;font color="gray"&gt;?? &lt;/font&gt;&lt;font color="blue"&gt;string&lt;/font&gt;&lt;font color="black"&gt;.Empty&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dt.Rows.Add&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;dr&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;resourceset.Close&lt;/font&gt;&lt;font color="gray"&gt;();&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;Later, I&amp;#39;m accessing an individual resource property like this:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:12px;"&gt;&lt;font color="black"&gt;&amp;nbsp;MyImage.ImageUrl &lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="black"&gt;MyResourceClass.MyResourceProperty&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br /&gt;&lt;/font&gt;&lt;/pre&gt;&lt;pre style="font-size:12px;"&gt;When I access the individual resource property, I get the following error:&lt;br /&gt;&lt;br /&gt;&lt;pre id="ErrorDetail"&gt;System.ObjectDisposedException: Cannot access a closed resource set&lt;/pre&gt; Obviously, the thing to try is to remove the &amp;quot;resourceset.Close()&amp;quot; statement from the first statment, and that does the trick.  But the code is based&lt;br /&gt;&amp;nbsp;on code examples I&amp;#39;ve found in various sources, and they all have a while loop followed by a close.&lt;br /&gt;&lt;br /&gt;My guess is that the resource class handles things a bit differently than some examples I&amp;#39;ve seen (which may have been based &lt;br /&gt;on pre-Asp .Net 2.0 methods to access resources).  From what I can tell, in Asp .Net 2.0 and later, a resource manager is allocated&lt;br /&gt;for each resource the first time a resource is requested, and resource assemblies are loaded into the application domain on first &lt;br /&gt;access, and remain there until the application domain is unloaded.&lt;br /&gt;&lt;br /&gt;So, does this mean that one should never close the resource file?  Are there problems associated with not closing the&lt;br /&gt;resource file?  And, if one follows the examples from the web, closing the resource manager, how does one check &lt;br /&gt;for a closed resource and then open the resource if it&amp;#39;s closed? &lt;br /&gt;&lt;/pre&gt;&lt;/pre&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>