.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Error in Web Setup Project while using Installer Class aError in Web Setup Project while using Installer Class and Custom Actions "Object reference not set to an instance of an object"nd Custom Actions "Object reference not set to an instance

Posted By: Vuyiswa Maseko     Posted Date: February 06, 2009    Points:2   Category :ASP.Net
Good Morning All

I have a WebSetup Project and a Installer Class. I want to accept User





Database ServerUsernamePasswordE-mail

This is what i did so far. I have created a Websetup Class installer that looks like this



namespace ClassLib{ [RunInstaller(true)] public class ClassLib : Installer { public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver); // Retrieve configuration settings string targetSite = Context.Parameters["TargetSite"]; string targetVDir = Context.Parameters["TargetVdir"]; string targetDir = Context.Parameters["TargetDir"]; if (targetSite.StartsWith("/LM/")) targetSite = targetSite.Substring(4); writeEventLogs(); //adjust the web.config file. createConnectionString(targetSite, targetVDir, targetDir); //create ASP.Net 2 site... RegisterScriptMaps(targetSite, targetVDir); } void RegisterScriptMaps(string targetSite, string targetVDir) { // Calculate Windows path string sysRoot = System.Environment.GetEnvironmentVariable("SystemRoot"); //get the latest .net framework directory DirectoryInfo di = new DirectoryInfo(sysRoot + "/Microsoft.NET/Framework"); DirectoryInfo[] frameworkDir = di.GetDirectories("v2.0.*", SearchOption.TopDirectoryOnly); int big = 0; for (int i = 0; i < frameworkDir.Length; i++) { int current = Convert.ToInt32(frameworkDir.Name.Substring(5)); if (current > big) { big = current; } } string latestFramework = di.FullName + "\\v2.0." + big.ToString(); // Launch aspnet_regiis.exe utility to configure mappings ProcessStartInfo info = new ProcessStartInfo(); info.FileName = latestFramework + "\\aspnet_regiis.exe"; info.Arguments = string.Format("-s {0}/ROOT/{1}", targetSite, targetVDir); info.CreateNoWindow = true; info.UseShellExecute = false; Process.Start(info); } void writeEventLogs() { //for debugging purposes write these values to eventlog. //EventLog.WriteEntry("o!Web Server", Context.Parameters["Server"]); //EventLog.WriteEntry("o!Web User", Context.Parameters["Username"]); //EventLog.WriteEntry("o!Web Password", Context.Parameters["Password"]); //EventLog.WriteEntry("o!Web Target Directory", Context.Parameters["TargetDir"]); //EventLog.WriteEntry("o!Web Target Site", Context.Parameters["TargetSite"]); //EventLog.WriteEntry("o!Web Virtual Directory", Context.Parameters["TargetVdir"]); } void createConnectionString(string targetSite, string targetVDir, string targetDir) { // Retrieve "Friendly Site Name" from IIS for TargetSite DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite); string friendlySiteName = entry.Properties["ServerComment"].Value.ToString(); //set the connection timeout property entry.Properties["ConnectionTimeout"][0] = 1800; entry.CommitChanges(); entry = new DirectoryEntry("IIS://LocalHost/" + targetSite + "/ROOT/" + targetVDir); entry.Properties["AspScriptTimeout"][0] = 1800; entry.Properties["AspSessionTimeout"][0] = 60; entry.CommitChanges(); FileSecurity fSecurity = File.GetAccessControl(targetDir + "App_Data"); //string DomainUserName = Environment.UserDomainName + "\\IUSR_" + Environment.MachineName; string LocalUserName = Environment.MachineName + "\\IUSR_" + Environment.MachineName; string LocalGroupName = Environment.MachineName + "\\IIS_WPG"; // Add the FileSystemAccessRule to the security settings. try { fSecurity.AddAccessRule(new FileSystemAccessRule(LocalGroupName, FileSystemRights.FullControl, AccessControlType.Allow)); fSecurity.AddAccessRule(new FileSystemAccessRule(LocalUserName, FileSystemRights.FullControl, AccessControlType.Allow)); //fSecurity.AddAccessRule(new FileSystemAccessRule(DomainUserName, FileSystemRights.Write, AccessControlType.Allow)); // Set the new access settings. File.SetAccessControl(targetDir + "App_Data", fSecurity); } catch { } // Open Application's Web.Config Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName); config.AppSettings.Settings["installpath"].Value = targetDir.Substring(0, targetDir.Length - 1); config.AppSettings.Settings["DBuser"].Value = login(); config.AppSettings.Settings["adminEmail"].Value = Context.Parameters["adminEmail"]; config.ConnectionStrings.ConnectionStrings["DBConnectionString"].ConnectionString = connectionString("oDirectv3"); config.ConnectionStrings.ConnectionStrings["oDirectConnectionString"].ConnectionString = connectionString("oDirectv3"); ((CompilationSection)config.GetSection("system.web/compilation")).Debug = false; //save web.config config.Save(); } string connectionString(string db) { string server = string.Empty; if (Context.Parameters["Server"] != string.Empty) { server += "Data Source=" + Context.Parameters["Server"] + ";Initial Catalog=" + db + ";Persist Security Info=True;" + login(); } return server; } string login() { //User ID=o;Password=abacus string login = string.Empty; if ((Context.Parameters["Username"] != string.Empty) && (Context.Parameters["Password"] != string.Empty)) { login += "User ID=" + Context.Parameters["Username"] + ";Password=" + Context.Parameters["Password"]; } return login; } public override void Uninstall(IDictionary savedState) { base.Uninstall(savedState); } public override void Commit(IDictionary savedState) { base.Commit(savedState); } public override void Rollback(IDictionary savedState) { base.Rollback(savedState); } }}

After that i went to the user interface and added a "Textboxes(A)" and the Properties are like this



EDITA1 = Database Server:EDITA2 = Username:EDITA3 = Password:EDITA4 = System Administrator Email Address:

After here i have created the output(Primary) for the Class Project and for my Website its contents and moved them to the bin Directory.

After that i have created a Cumstom action and i went to the install and Add the Project that is in the bin Derectory and went to the Properties of the Custom Action for install and Added the Following in the "Custom Action Data" Property.




/installpath ="[ EDITA1]\" / DBuser ="[ EDITA2]" /password="[ EDITA3]" / adminEmail ="[ EDITA4]"

Well am not sure about what i have wrote here , your help will be apreciated. After i have done that i have build my setup Project and it came back with no Errors or warning and i tried to install the setup and i filled in the server,username,password and e-mail and after that it continues to install and at the end it gives an Error




"Object reference not set to an instance of an object"

What is it that am Doing wrong ?

Thank you

Responses
Author: Amit Mehra             
Posted Date: February 19, 2009     Points: 5   

Hi Vuyiswa Maseko,

can't able to read the code..Just one cents from me..set CustomAction property and see that might resolve your problem.

Regards
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Amit Mehra             
Posted Date: February 19, 2009     Points: 5   

Hi Vuyiswa Maseko,
can't able to read the code..Just one cents from me..set CustomAction property and see that might resolve your problem.

Sorry for repeated answer..by mistake pressed two times submit button

Regards
Amit

Thanks,
Amit
Please "Mark As Answer " if this post help you.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend