Solved

app.config in Visual Studio Project Template Wizard

Posted on 2009-04-08
2
700 Views
Last Modified: 2012-05-06
I am trying to create a Template Wizard in C# for adding Project Items to a project in Visual Studio and am running into some problems regarding app.config files.  

Essentially I am trying to replace a separate application that was made by my company for creating ORM objects for their own custom ORM system.  However though, I've been told that even in utilizing my own Template Wizard, I still have to instantiate and use their own logging mechanisms that they've created in C#.

So, from the template wizard's dll (which I have strongly named and installed to the GAC), here is the line where I have trouble.

                Assembly cricketRunAsm = Assembly.Load("Cricket.Core.UI");
                Type runType = cricketRunAsm.GetType("Cricket.Core.UI.Start");

(Cricket is the name of their framework, and it's not strongly-named either, so basically I copy it to the current directory (which in my case is C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE running from the Wizard), and then load the assembly.  Then I try to instantiate the Start class which is the startup class to instantiate all of the logging and everything.  From the Wizard I get an error when instantiating this class though, doing a little more debugging I found that the problems happen on this section of code in their core:

            String primaryServer = System.Configuration.ConfigurationManager.AppSettings["PrimaryBootStrapServer"];
            String secondaryServer = System.Configuration.ConfigurationManager.AppSettings["SecondaryBootStrapServer"];
            String tertiaryServer = System.Configuration.ConfigurationManager.AppSettings["TertiaryBootStrapServer"];

Essentially, these are all coming up blank because there is no app.config for the Template Wizard app, and thus the core code is failing when instantiated since there is no server to point to (and unfortunately I have no control over changing their core code), they use these settings to determine a server name to point to for their services.  I can of course find these server settings off of their SVN server and have seen the app.conig that they use, but I have no way of getting them to into ConfigurationManager.AppSettings when calling this dll as a Template Wizard inside VS.

Any ideas?

I tried some suggestions from this site as well:
http://www.codeproject.com/KB/dotnet/dllappconfig.aspx

As it shows how to point to a separate .config file and load it as the application's config, this seems to work fine when running from a standalone application running the dll, but not as a template wizard running inside VS.
0
Comment
Question by:BitRunner303
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
BitRunner303 earned 0 total points
Comment Utility
Nvm I managed to figure it out...

(from inside the GAC installed template wizard DLL):

                string confPath = Assembly.GetExecutingAssembly().Location + ".config";
                ExeConfigurationFileMap fMap = new ExeConfigurationFileMap();
                fMap.ExeConfigFilename = confPath;

                Configuration conf = ConfigurationManager.OpenMappedExeConfiguration(fMap, ConfigurationUserLevel.None);
                ConfigurationManager.AppSettings["PrimaryBootStrapServer"] = conf.AppSettings.Settings["PrimaryBootStrapServer"].Value.ToString();
                ConfigurationManager.AppSettings["SecondaryBootStrapServer"] = conf.AppSettings.Settings["SecondaryBootStrapServer"].Value.ToString();
                ConfigurationManager.AppSettings["TertiaryBootStrapServer"] = conf.AppSettings.Settings["TertiaryBootStrapServer"].Value.ToString();

Works like a champ.
0
 
LVL 3

Author Comment

by:BitRunner303
Comment Utility
Comment: I called this before creating an instance via Activator.CreateInstance(runType), so that once the inner dll gets called and ask for Configuration.AppSettings["blah"] the proper values will be there.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
import issue in bit values 3 43
Linq help 1 16
ConsoleSql 1 12
Split string on commas but not when enclosed in parentheses 7 21
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now