How To : Get Enterprise Library to work Whidbey Beta 2


Beta 2 is out and Enterprise Library doesn’t work .   The problem is a few regression bugs in Whidbey (most of them with the XmSerializer).  I have actually got everything working on Beta 2 and want to give you a few pointers to get it working.

  • If you don’t care about the obsolete classes / methods, you can turn off warning level 4 down to level 3 in each project properties. If not you have to fix all the errors from warnings. If you want to be really cool you can use pragmas (yeah they finally got it right (geez C++ has had the for a while now).
  • Any type in your configuration data that can be null can not be an abstract class.  The problem is that the XmlSerializer does not care that something is null (nil), it stills tries to instantiate the class.  To fix this, make any of these types concrete and not abstract.  The two biggest classes are TransformerData and KeyAlgorithmPairStorageProviderData.  So what most of you are seeing right now is that when you don’t specify a key storage provider for configuration, it blows up.  That is because it is trying to instantiate KeyAlgorithmPairStorageProviderData class which is abstract.
  • The XmlSerializer no longer supports the CDATA sections .  So in logging in the TextFormatterData class, you will have to change the template to something else like an XmlNodeList or if you don’t care about reading the template, a base64 encoded string.
  • The ConfigurationDesignHost implements the IDictionaryService interface.  Kill it.  Remove it completely. In truth, this was never supposed to work (according to the System.ComponentModel guys).  You are only to have one IDictionaryService per Site.  Ok another reason to remove it, no one ever uses it .  This should get the tool working.

Since this may not be everything (I just have had one pass through the code), post or email me other changes and I will try and keep this article up to date.

Now playing: SoundgardenJesus Christ Pose

Comments (34)

  1. Miguel says:

    Hey,

    I still get this error:

    Warning 9 Cannot find custom tool ‘StringResourceTool’ on this system. C:Program FilesMicrosoft Enterprise LibrarysrcLoggingSinksDatabaseSR.strings 0 0

    How do I fix this?

  2. James White says:

    Scott,

    Thanks, my morning (despite the rain) is already looking up!

    Miguel,

    You can pick up the string resource generator at:

    http://projectdistributor.readify.net/Releases/Release.aspx?releaseId=10

    If you download the latest source from that site, rename the file to string.zip (strangely is missing the extension), and unzip it there is an installation for the resource generator in there. Good luck!

  3. Thanks, Scott.

    Could you expand on bullet point 3, please? Assume it’s first thing in the morning and I have an awful head cold and don’t readily see what I need to do to this class. :)

  4. James White says:

    On point #3, basically you want to remove the IDictionaryService interface from the class (ConfigurationDesignHost) like this:

    public class ConfigurationDesignHost : ServiceContainer, IContainer, IComponentChangeService, IDictionaryService

    …becomes…

    public class ConfigurationDesignHost : ServiceContainer, IContainer, IComponentChangeService

    You’ll also want to remove this line (#50):

    AddService(typeof(IDictionaryService), this);

    And if you are feeling adventurous you can remove any of the methods that have ‘seealso cref="IDictionaryService.xxx", but I don’t think that is necessary.

  5. James White says:

    The changes seemed to go well, but the dreaded "ReadOnlyConfigurationSectionData is not found in schema" error is still there. I think you only see this if you are building the library into a web project (web.config).

    I tried to get around it by inferring an XSD from the configuration XML and then referencing that in the xmlns tag on the enterpriselibrary.configurationSettings element. I know it is kinda crazy, and I’m not sure why it makes any difference but it at least lets me run up until the point where it starts deserializing the configuration. I’m getting close tho! 8)

  6. James White says:

    Its working! Its working! ASP.NET 2.0 & Enterprise Library… seriously.. months I’ve been trying this.

    Ok..

    1.) Do everything above. On step 3 you can change the TextFormatterData templateData member to a string like this:



    private string templateData = string.Empty;

    [XmlElement("template")]

    public string Template

    {

    get { return Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(templateData)); }

    set

    {

    byte[] conv = Convert.FromBase64String(value);

    char[] chars = System.Text.Encoding.ASCII.GetChars(conv);

    this.templateData = new string(chars);

    }

    }

    2.) You’ll need to wipe out the CDATA section in the loggingdistributorconfiguration.config file and just leave <template></template> for now until it’s all working properly.

    3.) Move all the enterprise library configuration stuff to a subfolder in your website (like Configuration) including the entries in web.config (I created a new enterpriseLibrary.config to hold this using the web.config template VS generated)

    4.) Ok, here is where the real hack comes in. I’m certain there is a better way, but I’m desperate.. Since the configuration code looks to web.config by default, and I couln’t determine how to change this, I added this line to the ConfigurationBuilder at #577 just before it loads the configuration.

    configurationFile = configurationFile.Replace("web.config", "Configuration\enterpriseLibrary.config");

    So instead of looking at web.config (which is now empty of EntLib stuff so VS is happy), it looks into the Configuration subfolder for the ‘enterpriseLibrary.config’ file and works from there.

    5.) You may get an error when the logger tries to access the security event log.. Another hack, but I went into regedit and gave ASPNET permissions to read/write this section and it went away. Here is the key I changed the permissions on:

    HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesEventlogSecurity

    Phew…

    So, very good luck to all and if you are unable to build the library in VS2005, you can email me at questions@rationalpath.com for suggestions.

    Thanks Scott!

  7. Adam Saxton says:

    When i change KeyAlgorithmPairStorageProviderData from being abstract to just public class KeyAlgorithmPairStorageProviderData : ProviderData, ICloneable

    It barked that TypeName wasn’t implemented from ProviderData Class. So i put it in as override. But then the CustomKeyAlgorithmPairStorageProviderData barked with: System.InvalidOperationException: Member ‘CustomKeyAlgorithmPairStorageProviderData.TypeName’ hides inherited member ‘KeyAlgorithmPairStorageProviderData.TypeName’, but has different custom attributes

    I understand why i’m getting the exception but not sure how to get around it. It won’t let me set TypeName as virtual within KeyAlgorithmPairStorageProviderData because it is overriding the one from ProviderData.

    What am i missing?

  8. Miguel says:

    Hi,

    I’m almost there. I guess the sunshine and warm weather helped :). I can build the solution and start the tool application but when I try to save the configuration I get ‘object reference not set to an instance of an object. It’s a System.NullReferenceException. I suspect it’s related to scott’s #2 issue. Scott(or anyone), could you elaborate more on it, specially this part that I don’t understand ‘To fix this, make any of these types concrete and not abstract.’ ?

    Thanks!

  9. wizardnet says:

    Hello,

    I just removed the abstract attribute for the classes that you mention, but now I am stuck with an exception on ConfigurationManagerSectionHandler.Create method.

    The folowing line of code throw an exception:

    XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationSettings));

    "There was an error reflecting type Microsoft.EnterpriseLibrary.Practices.Configuration.ConfigurationSettings"

    I am using VS 2005 Beta 2

  10. wizardnet says:

    I get it working in the following way:

    After removing abstract from the two classes TransformerData and KeyAlgorithmPairStorageProviderData, you should add a public default contructor to the classes (it seems that it is required while XmlSerializer reflects on types).

    You also should declare and define the TypeName property as following:

    [XmlAttribute("type")]

    public override string TypeName

    {

    get { return typeof TransformerData).AssemblyQualifiedName; }

    set {}

    }

    respectivelly

    [XmlAttribute("type")]

    public override string TypeName

    {

    get { return typeof KeyAlgorithmPairStorageProviderData).AssemblyQualifiedName; }

    set {}

    }

    It should work then…

    Regards

  11. James White says:

    No more "ReadOnlyConfigurationSectionData is not found" ! 8)

    In case you are still struggling with the changes, I’ve built a <soooper>Unofficial</soooper> release of the Enterprise Library for ASP.NET 2.0 assemblies which can be downloaded from the URL below. All the assemblies are signed, so you can also install them right to the GAC if you wish.

    Thanks!

    James

    http://www.rationalpath.com

  12. Adam Saxton says:

    I got it to build succesfully, but i had to do a few extra things not listed by Scott.

    For every project, changing the warning level from 4 to 3 did not remove the obsolete class/method warnings. I had to list warning number 0618 to the supress warnings text box. I also had to list 1717 to the Logging and ExceptionHandling.Logging projects because a field was begin set to itself. Other than that i didn’t have an issue. Just thought i would list this in case anyone else ran into it.

  13. Ram says:

    So I started compiling EL on VS.NET 2005. Everything works fine after a few tweaks but the web.config file does not like the tag "enterpriselibrary.configurationSettings", but later on that works fine too. Now the web services and everything else works fine but when I run the project in Debug mode, I get I get following error:

    {http://www.microsoft.com/practices/enterpriselibrary/08-31-2004/configuration}XmlFileStorageProviderData is not found in Schema.

    I am pulling my hair…need some assistance. I would want to keep all these settings in Web.config.

    Thanks,

    Ram

  14. jwright says:

    Hi,

    I have compiled parts of the library with Beta 2 of VS. Specifically, I am working on Configuration, Common and the Confiuration Console. I am past the XmlSerializer problems described in previous posts, but the output configuration files generated by the console only include the root node. I am suspecting more serialization problems. Can you provide any guidance on how to solve this?

  15. Rick.Blog says:

    Ok,&amp;nbsp; This one took a lot of people a lot of time.&amp;nbsp; It took me a couple days to compile the…

  16. Rick Kierner says:

    I don’t know how many of you are having the same problem I did. I am working now (Thank God.) I put together a quick list of exactly what I did to get myself up and running with enterprise library 1.9.9.9 from Jason White:

    http://www.midwestcoders.net/blogs/ricks_blog/archive/2005/05/05/20.aspx

  17. Ram says:

    So I implemented James’ and Rick’s solution but the hack for web.config in ConfigBuilder.cs doesn’t work with me because I am also using WSE 2.0 and this hack will break my code on client. Additionally, isn’t there another way to get around it without the hack?

    Thanks,

    Ram

  18. We are trying to get the EnterpriseLibrary to work in Visual studio 2005 beta 2. We want to use the library in the smart client application. Does anyone have the full version compiled and tested under 2005 beta 2? While compiling in beta 2,we changed the obsolete namespaces and are able to compile in beta 2. However there are NUNit test cases attached to it which fail. Most of them are on the XML seralizer. After applying the changes mentioned by Scott some of them passed. But there are still some which fail. Its basically in Configuration block where it expects a XML of certain type. like xmlns:xsd="http://www.w3.org/2001/XMLSchema“>http://www.w3.org/2001/XMLSchema" " +"xmlns:xsi="http://www.w3.org/2001/XMLSchema“>http://www.w3.org/2001/XMLSchema-instance" " +

    but it receives the string like "mlns:xsi="http://www.w3.org/2001/XMLSchema“>http://www.w3.org/2001/XMLSchema-instance" first and then the "xmlns:xsd="http://www.w3.org/2001/XMLSchema“>http://www.w3.org/2001/XMLSchema" and the test case fails. Has anyone encountered the problem and know a work around. Any help would be appreciated.

    -Vishal Karnik

  19. Leon Breedt says:

    Perhaps Microsoft could learn from the OSS community here and supply the changes as a plaintext diff/patch file?

    Applying a patch is a lot easier than having to manually comb through the source code and replicate disparate changes and hope you got it right.

  20. Shmulik says:

    Hi everybody,

    I have dowloaded the following version for starting to get it works with 2005 beta 2:

    http://www.midwestcoders.net/blogs/ricks_blog/archive/2005/05/05/20.aspx.

    Each time i try to add a reference to the configuration assembly then i got yellow exclamation mark on this reference and i can’t compile it.

    Does anyone know what is the problem ?

    Cheers,

    Shmulik

  21. Benoit says:

    For the exclamation with reference, i got the same problem … Just put your reference in a shorter path (like c:reference…) and it will work !

  22. Benoit says:

    Ok enterprise 1.9.9.9 work in winform, but in web I still have problem with configuration, I do everything in http://www.midwestcoders.net/blogs/ricks_blog/archive/2005/05/05/20.aspx, token key and version are correct, web.config doesn’t have anything about EL, I make the ‘Configuration’ repertory and copy all the .config, but when i ask for database instance name it is still empty ? Any idea?

    Benoit

  23. Okay, so here’s how you get Enterprise Library to work with Visual Studio 2005, http://blogs.msdn.com/scottdensmore/archive/2005/04/27/412420.asp

  24. Okay, so here’s how you get Enterprise Library to work with Visual Studio 2005, http://blogs.msdn.com/scottdensmore/archive/2005/04/27/412420.asp

  25. How to get enterprise library to work with beta 2.

  26. Okay, so here’s how you get Enterprise Library to work with Visual Studio 2005, http://blogs.msdn.com/scottdensmore/archive/2005/04/27/412420.aspx….