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


Post New Web Links

problem reading from app.config

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :.NET Framework
 

I have added an app.config file in my winform aplicaion an added one key

<add key="IsFirstRun" value="True" />

then I am tying to read it like this:

MessageBox.Show(ConfigurationManager.AppSettings["IsFirstRun"]);

but I am getting this error:

Configuration system failed to initialize

on the MessageBox line..

why? how ca I fix please?


Jassim Rahma


View Complete Post


More Related Resource Links

Problem when using Activator.CreateObject and reading App.Config file

  
Hello, this is the scenario. I have an application that load at runtime severals dll. these dll are actually "adapters" that wraps calls to web services, database and so on. The app.config of the "main" application stores in config sections all information necessary to each adapter (i.e.Web ServiceURL..) and I have created inside each adapter a class to ready those values the loading at run time the DLL has been implemented by storing all necessary types into a dictionary of generics and when I need to instanciate it I call the Activate.CreateObject and I pass the specific type (I means the name of the Adapter class) The problem is that the adapter class itself is not able to get the config value because ConfigSection has not been initialized. If I write: IInterfaceAdap adapt = new myAdapter() -> I read the config data IInterfaceAdap adapt = (IInterfaceAdap)Activator.CreateObject (type) -> now way to read the data stored in the App.Config. I think that I undertood the problem but I'm not able to find a workaround to read data store in the app.config!! I need help please!!  

reading values from config files in NUnit tests

  

One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?


Razor View Engine and Add Namespace in Web.Config Problem

  

Hello,

I am working on a MVC project with Razor view engine and I have the following:

  @MvcHtmlString.Create(
    Bundle.Css()
      .Add("~/Styles/FlyOnDreams.FlyOnPages.Base.css.less")
      .Add("~/Styles/FlyOnDreams.FlyOnPages.Core.css.less")
      .Render("~/Styles/FlyOnDreams.FlyOnPages.Core.min.css"))


This only works if I have on the same view the following:

  @using SquishIt.Framework;

However, on my Web.Config I have the following:

    <pages>

      <!-- Namespaces -->
      <namespaces>
        <add namespace="System"/>
        <add namespace="System.Web.Mvc"/>
        <add namespace="System.Web.Mvc.Ajax"/>
        <add namespace="System.Web.Mvc.Html"/>
        <add namespace="System.Web.Routing"/>
        <add namespace="Microsoft.Web.Mvc"/>
        <add namespace="SquishIt.Framework"/>
      </namespaces>

    </pages>


So if "SquishIt.Framework" namespace is added on Web.Config why do I need to have the @using on the view?

reading excel file problem

  

Hi,


i have 200 rows in my excel file. im using OleDbConnection to read the excel file.

The problem is that it will read all the blank rows from row 200 onwards. Is there a configuration im missing ? or is there a way to import all rows that has data? Here's some of my code.


string excelConnectionString =
               "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + filePath + ";" +
                "Extended Properties=Excel 8.0";

OleDbConnection excelConnection =
                    new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=NO'");


OleDbCommand cmd = new OleDbCommand("Select * from [list$]",excelConnection);







Problem reading my DLL

  
Hi there, I have a problem trying to display my DLL on Visual Studio 2005. I created a windows control library and I want to access it from my asp/c# website. I use the following code to display it: <object id="myComponent" classid="http:WindowsControlLibrary1.dll#WindowsControlLibrary1.UserControl1" height="300px" width="100%" />However, when I run the website it just shows me a plain box. With nothing in it.Another thing, the VIEWASTEXT inserted in the object it gets underlined and when I roll the mouse over it says:"VIEWASTEXT attribute is not valid attribute of element 'object'"Can anyone help me go around this problem or fix it?Thank you in advance ;)

Problem reading from cookie

  
I'm trying to build a smaller shop and I have run into some problems with cookies. This is my code in the shoppingcartaccess classprivate static string shoppingCartId { get { // get the current HttpContext HttpContext context = HttpContext.Current; // try to retrieve the cart ID from the user cookie string cartId = context.Request.Cookies["CartID"].Value; // HERE I GET THE ERROR // if the cart ID isn't in the cookie... // check if the cart ID exists as a cookie if (context.Request.Cookies["CartID"] != null) { // return the id return cartId; } else // if the cart ID doesn't exist in the cookie as well, generate // a new ID { // generate a new GUID cartId = Guid.NewGuid().ToString(); // create the cookie object and set its value HttpCookie cookie = new HttpCookie("CartID", cartId); // set the cookie's expiration date int howManyDays = SiteConfig.CartPersistDays; DateTime currentDate = DateTime.Now; TimeSpan timeSpan = new TimeSpan(howManyDays, 0, 0, 0); DateTime expirationDate = currentDate.Add(timeSpan); c

Error reading .config file in Windows Forms app - Access is denied

  
I'm attempting to read a connection string from a .config file in a Windows Forms app on a test laptop. A previous version of the application worked just fine, but now I get a configuration exception thrown - "Configuration system failed to initialize." The inner exception message says - "An error occurred loading a configuration file: Access is denied". The user I'm logged in as is in the Administrators group and there's no obvious problems with the config file. The same config file works just fine on my dev machine so it's not an issue with ordering of the XML. Any ideas would be greatly appreciated.If a response to your question is helpful or answers it please mark it as such!

Error reading .config file in Windows Forms app - Access is denied

  
I'm attempting to read a connection string from a .config file in a Windows Forms app on a test laptop. A previous version of the application worked just fine, but now I get a configuration exception thrown - "Configuration system failed to initialize." The inner exception message says - "An error occurred loading a configuration file: Access is denied". The user I'm logged in as is in the Administrators group and there's no obvious problems with the config file. The same config file works just fine on my dev machine so it's not an issue with ordering of the XML. Any ideas would be greatly appreciated.If a response to your question is helpful or answers it please mark it as such!

DB Reading problem

  
I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

DB Reading problem

  
I was having problem with my database, I couldn't see any of the table in the enterprise manager. when I execute any sql in some of the tables of the database it was giving error msf that "Bad Page Id". I went through the FAQs and Forums, I tried with this queries. ALTER DATABASE DMS_PILOT SET SINGLE_USER go DBCC CHECKDB (DMS_PILOT, REPAIR_ALLOW_DATA_LOSS) GO When I execute this query I found some new error messeges mentioned as below. "Server: Msg 8966, Level 16, State 1, Line 2 Could not read and latch page (1:3168) with latch type SH. sysindexes failed. DBCC execution completed. If DBCC printed error messages, contact your system administrator." Please help me.

WCF Reading Endpoint Behaviors from a web.config file

  

Hi

I've got a WCF service which has multiple clients that it connects to.

What I want to do is to create the clients dynamically the WCF services consumes.

Creating the clients by inheriting from the `ServiceFactory<TChannel>` class is done and very simple. What I'm struggling with is how to read Endpoint behaviours from the `web.config` file and add them to the clients?

Code file

    BasicHttpBinding binding = new BasicHttpBinding(bindingConfigName);
    EndpointAddress endpoint = new EndpointAddress(endpointUrl);
    ChannelFactory<IShoppingSoap> clientEndpoint = new ChannelFactory<IShoppingSoap>(binding, endpoint);
   
    base.Endpoint.Behaviors.Add(*Get the behavior from the config file*);
    return base.CreateChannel();

`Web.config` file :

    <behaviors> 
        <endpointBehaviors> 
           <behavior name="EndpointBehaviour_GmCustom">
             <dataContractSerializer maxItemsInObjectGraph="2147483646" /> 
      

web.config problem

  

I have a subdomain mobile.JassimRahma.com and that's referring of course to a folder on my root called mobile.

I just created a simple, very simple Default.aspx file and placed in the mobile folder but I am getting thie error:

Runtime Error 
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 

Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".


 

 

and this is my SIMPLE Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Jassim.mobile.Default" %>
<%@ OutputCache Duration="120" VaryByParam="None" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD

XMLDocument, problem reading Node.

  

Hello,

 

I am doing the following:

 

System.Net.WebRequest myRequest = System.Net.WebRequest.Create("http://www.atlantawithkid.com/feed/"); 
System.Net.WebResponse myResponse = myRequest.GetResponse(); 
 
System.IO.Stream rssStream = myResponse.GetResponseStream(); 
System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); 
rssDoc.Load(rssStream); 
 
System.Xml.XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item"); 
System.Xml.XmlNode rssDetail; 
 
string sRssDescription;  
rssDetail = rssItems.Item(0).SelectSingleNode("description"); 
if (rssDetail != null) 
    sRssDescription = rssDetail.InnerText; 

However, when I read the "description" node and view the InnerText, or the InnerXML, the string is different than in the original XML document.

The string returned has and ellipses and the data is truncated. However, in the original XML document there is data that I can see.

Is there a way to select this node without the data being altered?

The original XML <description> node is as follows:

			<description xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" cf:type="html">
				<div class="tweetmeme_button" style="float:right;margin-le

web.config connection string problem within VisualStudio 2010 to point to SQL Server 2008 R2 Develop

  

Hello All, I would appreciate any help with this.

I believe my problem exists within the web.config which already had code in it to connect to SQL Server Express 2008.

I uninstalled the SQL Server Express that came with Visual Studio 2010.

I installed SQL Server 2010 R2 Developer, and I'm able to connect via Management Studio and through Visual Studio's Server Explorer's Data Connections I am connected.

I did run aspnet_regsql.exe within the 4.0 folder in order to create the database with Microsoft Service Providers.

Here is the ServerName: USER-5529234649 

Here is the name of the DataBase:  StepByStepChapter9

Here is the name of the Connection within Visual Studio's Server Explorer's Data Connections:  user-5529234649.StepByStepChapter9.dbo

Here is the code I changed in the web.config:

<connectionstrings>
<add name="ApplicationServices" c

StreamReader.BaseStream.Read() problem in Random access reading of file

  

I am trying to randomly access a file but not fully understanding this class.

I have

 // Seek to the beginning of the field

System.IO.StreamReader srFile = new System.IO.StreamReader(_FileName.PathAndFileName);

srFile.BaseStream.Seek(FieldOffset, SeekOrigin.Begin);







// Read the field



int FieldLength = Field.FieldLength;  







int BUFFER_SIZE = (int)RecordLength;



byte[] bBuffer = new Byte[BUFFER_SIZE];



srFile.BaseStream.Read(bBuffer, 0, (int)FieldLength);



srFile.Close();
string FieldValue;
FieldValue = bBuffer.ToString();

but bBuffer is numbers like:

[0] 32
[1]32
[2]32
etc..

and the value of FieldValue is "System.Byte[]"

I'm trying to get text as this is a text file.

 


Problem in reading WCF configuration settings

  

Hi,

The great thing about WCF is that you can configure you're WCF bindings in a configuration file and not through code.
We are now making connection to WCF's webservices in our SharePoint code, but now the question is where to place the WCF configuration settings. 

 

For deployment reasons we don't want to place the settings in the SharePoint web.config:

-  can't be easily changed by admin users through SharePoint Gui

-  new deployment needed to change configuration settings

-  webservices u

Problem in the Console Applications app.config file for .NET 4.0

  

Team

I am developing a console application.  I am going to use that in 3 environments. I have placed a key in the appsetting section and i am expecting the value to be overwritten by the respective config file specified during the build time.

<configuration>
    <appSettings file="Stage.config">
        <add key="DataConfiguration.ActiveLocation" value="Production"/>
</appSettings>
<connectionStrings>
        <clear/>
        <add key =name="Dev.Local" providerName="System.Data.SqlClient" connectionString="data source=Test\SQLSERVER2005;initial catalog=ABCD;user id=admin;password=asdh511"/>
</connectionStrings>
</configuration>

And the Stage.config values are

<appSettings>
<add key="DataConfiguration.ActiveLocation" value="Staging"/>

</appSettings>

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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