I'm trying to use a config file by directing there from App.config.
I have created a folder named Config inside my solution and created a new config file named Environment.config.
My App.Config looks as following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<appSettings configSource="Config/Environment.config"/>
</configuration>
and the Environment.config looks as the following:
<appSettings>
<add key="URL" value="http://foo.aspx"/>
</appSettings>
I'm getting an error which says:
Result Message:
OneTimeSetUp: System.Configuration.ConfigurationErrorsException : Configuration system failed to initialize
----> System.Configuration.ConfigurationErrorsException : The configSource attribute must be a relative physical path, so the '/' character is not allowed. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22)
I have tried to switch from "/" to "\" but got a different error.
Result Message:
System.Configuration.ConfigurationErrorsException : Unable to open configSource file 'Config\Environment.config'. (D:\tfs\QA - Automation\Projects\ReportAppeal\ReportAppeal\bin\Debug\ReportAppeal.dll.config line 22)
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
I'll probably need to change the way I'm directing the Environment.config file but I'm not sure how.
As the error says:
The configSource attribute must be a relative physical path
So you will need to change your key to a physical path, not a relative one:
<appSettings configSource="C:\Config\Environment.config"/>
Or just leave it under the root:
<appSettings configSource="Environment.config"/>
Related
I am absolutely at my wits end with this, having tried basically everything. I also do not see any existing stackoverflow threads about doing this.
I have an app.config file for my C# project, and it stores a list of servers which the user can create and add to.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="servers" type="System.Configuration.AppSettingsSection" />
</configSections>
<servers>
<add key="server" value="678,true,true"/>
</servers>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
<appSettings>
<add key="nightmode" value="Dark"/>
<add key="theme" value="Red"/>
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ControlzEx" publicKeyToken="69f1c32f803d307e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
((NameValueCollection)ConfigurationManager.GetSection("servers")).Add("server", $"{port}," + $"{ (dialogResult1 == MessageDialogResult.Affirmative) },{dialogResult2 == MessageDialogResult.Affirmative}");
When the user goes to add a new key the the "servers" section, it throws the below exception.
System.Configuration.ConfigurationErrorsException: 'The configuration is read only.'
I am bewildered why this is happening
you can try:
Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("test", "propertyValue");
config.Save(ConfigurationSaveMode.Modified, true);
System.Configuration.ConfigurationManager.RefreshSection("appSettings");
string test = ConfigurationManager.AppSettings["test"];
This get de appsettings section values.
Ps.: You need Install-Package System.Configuration.ConfigurationManager.
I ended up generating my own XML configuration, since that appears to be the best way to do things.
I'm trying to get ImageResizer working with the TinyCache plugin. (i'll be on ImageResizer Essential Edition).
I am under Windows 10 / IIS 10.0 with Integrated mode
I have a .net webform 4.7.2 website with the following NuGet packages installed:
ImageResizer (v4.2.5)
ImageResizer.Plugin.TinyCache (v4.2.5)
ImageResizer.WebConfig (v4.2.5)
My web.config is the following:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!--<section name="resizer" type="ImageResizer.ResizerSection" requirePermission="false" />-->
<section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
</configSections>
<!--check URL ~/resizer.debug.ashx-->
<resizer>
<!--Unless you (a) use Integrated mode, or (b) map all requests to ASP.NET,
you'll need to add .ashx to your image URLs: image.jpg.ashx?width=200&height=20
Using IIS7 Integrated mode or the Visual Studio web server? You can skip this step.
You also don't need to do this if you are using the .jpg.ashx syntax.-->
<pipeline fakeExtensions=".ashx" defaultCommands="autorotate.default=true" />
<plugins>
<add name="TinyCache" />
<!--<add name="VirtualFolder" virtualPath="~/" physicalPath="..\Assets" vpp="false "/>-->
<!--<add name="VirtualFolder" virtualPath="~/" physicalPath="../Assets" vpp="false "/>-->
</plugins>
</resizer>
<system.web>
<customErrors defaultRedirect="YourErrorPage.aspx"
mode="RemoteOnly">
</customErrors>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
<pages>
<namespaces>
<add namespace="System.Web.Optimization" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
<httpModules>
<!-- This is for IIS7/8 Classic Mode and Cassini-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</httpModules>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<!--This is for IIS7+ Integrated mode-->
<add name="ImageResizingModule" type="ImageResizer.InterceptModule" />
</modules>
</system.webServer>
</configuration>
When I disable the TinyCache plugin (simply comment the <add name="TinyCache" /> line) it works when I try to call an image to resize (e.g. http:///Assets/TestImage.jpg?height=100 ; the image is resized ; here I have an TestImage.jpg picture in the Assets folder in the root directory of my website)
I however I get a warning on the diagnostic page http:///resizer.debug.ashx indicating I should enable cache:
(Warning): NoCache is only for development usage, and cannot scale to production use.
So I enable the TinyCache plugin in web.config.
Then I get a warning on the diagnostic page http:///resizer.debug.ashx which I am unable to get rid off : (Warning): To potentially see additional errors here, perform an image resize request.
If I then try to resize a picture (e.g. http:///Assets/TestImage.jpg?height=100 .... or event (e.g. http:///Assets/TestImage.jpg.ashx?height=100 which I should not need in my case with Win10 - IIS 10 Integrated mode) I get the following error :
Note : the english version of this error (I'm in French) would be
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Worth noted, the file /App_Data/tiny_cache.cache is never created ! (I have however granted all privileges on this folder to the user running the IIS Pool.... as well as all users on my DEV box !)
If you have any idea/solution, many thanks in advance !
I'm considering using https://imageprocessor.org/ instead of ImageResizer as didn't come with any pain :)
You need to install the protobuf-net nuget package. Because the dll is missing, a FileNotFound exception is thrown, which in turn is converted to a 404 error.
I have an issue regarding the .NET postgreSQL provider package EntityFramework6.Npgsql. I have installed the following packages: EntityFramework 6.0.0, EntityFramework6.NpgSql 3.1.1, Npgsql 3.1.0.
Currently I have just started a WPF project so I'm using a simple standard DbContext and it looks like this:
public class TimetrackerDbContext : DbContext
{
public TimetrackerDbContext()
: base("name=DbConnection")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("public");
base.OnModelCreating(modelBuilder);
}
public virtual DbSet<MyEntity> MyEntities { get; set; }
}
public class MyEntity
{
public int Id { get; set; }
public string Name { get; set; }
}
Now in my App.config file I specify the connection string. I've been trying to use this connection:
<add name="DbConnection"
connectionString="User ID=xxx;Password=xxx;Host=xxx;Port=5432;Database=xxx;Pooling=true;"
providerName="System.Data.EntityClient" />
But when I run enable-migrations -contexttypename MyDbContext in the PM Console I get the following error:
Keyword not supported: 'user id'.
I tried specyfying the metadata, provider connection string but it also threw errors and it does not make much sense to use it in Code First. In case somebody it could be useful here's my whole App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<!--<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />-->
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<connectionStrings>
<add name="DbConnection"
connectionString="User ID=xxx;Password=xxx;Host=xxx;Port=5432;Database=xxx;Pooling=true;"
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The providerName of your connection string System.Data.EntityClient is for Database First (edmx) type connections where the actual provider is encoded in the connectionString value.
For Code First connections, the providerName should match the invariantName from the providers section. In your case, replace
providerName="System.Data.EntityClient"
to
providerName="Npgsql"
I am trying to do a little spike and I cannot get log file generated.
This is my NLog configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.2.4.0" newVersion="3.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<nlog throwExceptions="true"
internalLogLevel="Warning"
internalLogFile="Rebus.Tests.Output.NLog.Internal.log"
internalLogToConsole="true"
xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="normalLogfile" type="File" fileName="${basedir}/Rebus.Tests.Output.log" />
<target name="normalConsole" type="Console" detectConsoleAvailable="true" />
</targets>
<rules>
<logger name="NormalLog" minlevel="Trace" writeTo="normalLogfile, normalConsole" />
</rules>
</nlog>
</configuration>
And here is my static Main in the Console Application:
var logger = LogManager.GetLogger("NormalLog");
logger.Error("This is a log error line");
But nothing is logged neither LogFile nor Console.
The application.exe.config is in the bin/Debug runtime folder.
And I am looking for the log file with SearchEverything so it will found in any folder where it is.
Adding some information to this question if I put a breakpoint to inspect logger variable I can see no configuration was read:
Try to change
var logger = LogManager.GetLogger("NormalLog");
to
var logger = LogManager.GetLogger("normalLogfile");
because as far as I know you have to get the logger via target-name and not via rule-name.
//edit
Have you tried to remove the nlog attributes in you app.config? Just to be sure none of them is the problem.
When i add this code to app.config in Windows service program:
<quartz>
<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzScheduler"/>
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="2"/>
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz"/>
</quartz>
it tips:
Could not find schema information for the element `key`.
Could not find schema information for the attribute `quartz`.
Could not find schema information for the element `value`.
I am sure i have using job_scheduling_data_2_0.xsd file in background.
And predefine the quartz:
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
Where is the problem?And where to find the schema info?
And when is the label <quartz> namespace?
Where should i find the xsd file of quartz.net?
Normal reason is your config file lack of schema file like *.xsd in:..\Microsoft Visual Studio\Xml\Schemas folder.
You can omit these tips,it could not affect your program running.
Or you can write the xsd schema file by yourself.