Normally, I would call a static method in a C# library rather than coding this in a functoid. It’s easier to unit test, you get full Intellisense (automatic code completion), and it just seems easier. However, I’m at a new client, that doesn’t yet have a C# library. It’s really no big deal to add one, but the client thought it would be simpler to just do the entire thing in a C# Scripting Functoid. It’s my first change to their system, so I didn’t want to make it overly complicated. (My plan is to introduce BizTalk Deployment Framework as soon as possible.) It actually took longer because of the snags I hit.
By the way, this is BizTalk 2010 and Visual Studio 2010.
I did write the code in C#, tested it, then copied it into the functoid. Then I started getting this error.
The code wrapped some additional logic around this statement:
string databaseName = ConfigurationManager.AppSettings["CustomDatabaseName"];
This resulted in this compile error, even though System.Configuration was already being referenced by the project.
error btm1021: Inline Script Error: The type or namespace name 'ConfigurationManager' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?)
To get the code to work, I had to go back to the obsoleted code as follows:
string databaseName = System.Configuration.ConfigurationManager.AppSettings.Get("CustomDatabaseName").ToString();
If you compile the above in normal VS2010, you will get this warning; but for some reason in the BizTalk project, the same warning does not appear.
warning CS0618: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings'
This was starts to explain why it won’t work, based on your C# in-line script having to be embedded inside of the XSLT code.