Padarn OpenNetCF System.Argument.Exception when starting the server - c#

I'm getting a "OpenNetCf - Argument Exception" when I try to start the server on the desktop (windows 8.1)
Srvr = new OpenNETCF.Web.Server.WebServer();
Srvr.Start();
However, I can't see a problem with the config file. Any suggestions would be much appreciated.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="WebServer" type="OpenNETCF.Web.Configuration.ServerConfigurationHandler, opennetcf.web"/>
<section name ="httpRuntime" type="OpenNETCF.Web.Configuration.HttpRuntimeConfigurationHandler, opennetcf.web"/>
</configSections>
<WebServer
UseSsl="false"
LocalIP="0.0.0.0"
DefaultPort="80"
MaxConnections="20"
DocumentRoot=".\Inetpub\"
Logging="false">
<DefaultDocuments>
<Document>Login.aspx</Document>
</DefaultDocuments>
<VirtualDirectories />
<Cookies />
<Caching />
</WebServer>
<httpRuntime
maxRequestLength="4096"
requestLengthDiskThreshold="256" />
</configuration>

You are most likely attempting to use the Compact Framework version of the binaries. While the Padarn code base work for Compact Framework, Full Framework and Mono, the compiled assemblies are different and you must use the appropriate one based on your runtime environment.

Related

How to change default Bucket in app.config

My App.Config looks like this.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="couchbaseClients">
<section name="couchbase"
type="Couchbase.Configuration.Client.Providers.CouchbaseClientSection, Couchbase.NetClient"/>
</sectionGroup>
</configSections>
<couchbaseClients>
<couchbase useSsl="false">
<servers>
<add uri="http://localhost:8091/pools"></add>
</servers>
<buckets>
<add name="CBMigration" useSsl="false">
<connectionPool name="custom" maxSize="10" minSize="5"></connectionPool>
</add>
</buckets>
</couchbase>
</couchbaseClients>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
In that i given bucket name is "CBMigration" but still the entries are in default bucket only.
And my c# code for initializing cluster is _instance = new Cluster("couchbaseClients/couchbase");
I need to make the bucket as "CBMigration" for the Cluster i initialized using the app.config.
Where i am going wrong ?
Please help me...
I think there's a gap in documentation there. The bucket entries in are only used to provide customized defaults for the bucket's configuration. That is the use of ssl, connection pool tuning, etc...
But having just one bucket config entry like that doesn't actually change the behavior of OpenBucket(): the default bucket used by the client is always "default".
You still have to explicitly open the specific bucket you want, using OpenBucket(BucketName, BucketPassword)... It's just that once you do that, said bucket will be opened using tuning parameters found in its corresponding section in App.config instead of hardcoded default ones.
Does that make sense?

Variables in XML configuration

I'm trying to use xml configuration file in my project. Now it looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="replication" type="Project.Replication.ReplicationConfigSection, Project.Replication" />
<section name="processing" type="Project.Processing.ProcessingConfigSection, Project.Processing" />
</configSections>
<replication>
<streams>
<stream name="STREAM_DATA_14360" />
</streams>
</replication>
<processing dataStream="STREAM_DATA_14360" />
</configuration>
It works OK, but I'm confused with duplicates in it ("STREAM_DATA_14360").
Can you remind me, how to create variables in XML or something for data reusing to be acceptable in application configuration?
UPDATE:
In real life my configuration has much more sections. There is a value, which apeears in many of this sections: STREAM_DATA_14360. So I want to be able to change this value only in one place of config file, and in other places to use reference to it.
Speed of changing configuration - is the first reason for it.
Size of a file is a second, because values can be huge: STREAM_INFO_FUTURE_SESSION_CONTENTS_12421 (that is third-party names)
You can simply add this value in <appSettings> and access it as you are saying.
You can do this as below:
<appSettings>
<add key="StreamName" value="STREAM_DATA_14360"/>
</appSettings>
In the code, you can access it as below:
string streamName = ConfigurationManager.AppSettings["StreamName"];
Make sure to add reference to System.Configuration assembly before using this.
XML doesn't have any native expansion macros or templating - any scenario would require that you do a preprocess step or have the code that reads the config involved in substituting the value.
If those aren't redacted names though, it seems a simple search/replace would solve the problem without much of a concern on false positives.
You could put something together with T4 templates as a preprocessor, whether that's worth it really depends on how often you expect to modify this file.
It should also be possible to shoehorn the web.config transformation engine into doing the replacements, but you may have to write some hosting code for the XDT engine depending on how your config file is setup.
Apart from using external code that might (or might not) facilitate your life, you can define your own classes that inherit from ConfigurationSection, wherein you define and encapsulate your key/value pairs and use the ConfigurationProperty attribute.
Have look at http://msdn.microsoft.com/en-us/library/2tw134k3.aspx for more info on How to: Create Custom Configuration Sections Using ConfigurationSection.
EDIT: you can make references in xsd (check here)
Thanks for your answers. I agree with Mark, there's no support of variables or references in XML. But, in my case there's much simpler solution. I feel stupid now, but hope that it will help another slowpoke too.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="global" type="Project.GlobalConfigSection, Project" />
<section name="replication" type="Project.Replication.ReplicationConfigSection, Project.Replication" />
<section name="processing" type="Project.Processing.ProcessingConfigSection, Project.Processing" />
</configSections>
<global>
<streamNames>
<streamName name="STREAM_DATA_14360" id="1"/>
</streamNames>
</global>
<replication>
<streams>
<stream nameId="1" />
</streams>
</replication>
<processing dataStreamId="1" />
</configuration>
Consequence: need to edit code to use global section as a source of all long names
Advantage: fast renaming, reusability of values

dll Configuration file (dllName.dll.config)

I am developing a plugin for a .NET 4 application and I want to add a config file to the dll as I dont want to put the configuration in the main config file.
I have added the app.config t the project and it is correctly compile and dllName.dll.config generated.
Here is my configuration file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MyTabsConfig" type="NewApp.UI.MyTabsConfigHandler, NewApp.UI" />
</configSections>
<MyTabsConfig>
<MyTabs>
<MyTab Name="First" Leads="2" />
<MyTab Name="Second" Leads="4" />
<MyTab Name="Third" Leads="1" />
</MyTabs>
</MyTabsConfig>
</configuration>
Now I have 1 problems:
If I copy the file in the ExtraPlugins directory of my main application, NewApp.UI.dll cannot be found when calling GetSection("MyTabsConfig"). I think it is looking in the main application folder.
Thanks.
Have you tried something like this?
ConfigurationSection section = ConfigurationManager.OpenExeConfiguration("myConfig.config").GetSection("mySection");

Enyim Memcached issue over .Net MVC 3

I have win 2008 R2 server with .net mvc project and other Ubuntu Linux with memchaed installed.
I have Eniym Memcached connector to memcached.
But when I try to run any memcached query I get:
An error occurred creating the configuration section handler for enyim.com/memcached: Could not load type 'e.Caching.Configuration.MemcachedClientSection' from assembly 'Enyim.Caching'.
Enyim web.config section:
<configSections>
<sectionGroup name="enyim.com">
<section name="memcached" type="e.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />
</sectionGroup>
</configSections>
<enyim.com>
<memcached>
<servers>
<add address="10.10.10.10(not real ip, connect to other server)" port="11222" />
</servers>
<socketPool deadTimeout="00:00:10" />
</memcached>
</enyim.com>
Controller action:
using Enyim.Caching;
using Enyim.Caching.Memcached;
public string About()
{
MemcachedClient memCache = new MemcachedClient();
memCache.Store(StoreMode.Set, "testkey", "testcontent");
return "some string";
}
Where can be the problem?
There's a good example here.
I think you want "Enyim.Caching.Configuration.MemcachedClientSection" where you currently have "e.Caching.Configuration.MemcachedClientSection"

How to use a App.config file in WPF applications?

I created an App.config file in my WPF application:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appsettings>
<add key="xmlDataDirectory" value="c:\testdata"/>
</appsettings>
</configuration>
Then I try to read the value out with this:
string xmlDataDirectory = ConfigurationSettings.AppSettings.Get("xmlDataDirectory");
But it says this is obsolete and that I should use ConfigurationManager which I can't find, even searching in the class view.
Does anyone know how to use config files like this in WPF?
You have to reference the System.Configuration assembly which is in GAC.
Use of ConfigurationManager is not WPF-specific: it is the privileged way to access configuration information for any type of application.
Please see Microsoft Docs - ConfigurationManager Class for further info.
In my case, I followed the steps below.
App.config
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="POCPublishSubscribeQueueName" value="FormatName:Direct=OS:localhost\Private$\POCPublishSubscribe"/>
</appSettings>
</configuration>
Added System.Configuartion to my project.
Added using System.Configuration statement in file at top.
Then used this statement:
string queuePath = ConfigurationManager.AppSettings["POCPublishSubscribeQueueName"].ToString();
In your app.config, change your appsetting to:
<applicationSettings>
<WpfApplication1.Properties.Settings>
<setting name="appsetting" serializeAs="String">
<value>c:\testdata.xml</value>
</setting>
</WpfApplication1.Properties.Settings>
</applicationSettings>
Then, in the code-behind:
string xmlDataDirectory = WpfApplication1.Properties.Settings.Default.appsetting.ToString()
You have to reference System.Configuration via explorer (not only append using System.Configuration). Then you can write:
string xmlDataDirectory =
System.Configuration.ConfigurationManager.AppSettings.Get("xmlDataDirectory");
Tested with VS2010 (thanks to www.developpez.net).
Hope this helps.
You have to add the reference to System.configuration in your solution. Also, include using System.Configuration;. Once you do that, you'll have access to all the configuration settings.
This also works
WpfApplication1.Properties.Settings.Default["appsetting"].ToString()
You can change configuration file schema back to DotNetConfig.xsd via properties of the app.config file. To find destination of needed schema, you can search it by name or create a WinForms application, add to project the configuration file and in it's properties, you'll find full path to file.
There is a good article about Application settings on Microsoft.
According to that you need to:
manually create App.config file (from Project Context menu -> Add -> New Item... -> Application Configuration File.)
add required sections there (I'm using only application scope settings):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DevelopmentEnvironmentManager.WPF.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<applicationSettings>
<DevelopmentEnvironmentManager.WPF.Properties.Settings>
<setting name="SqliteDbFilePath" serializeAs="String">
<value>Database.db</value>
</setting>
<setting name="BackgroundColor" serializeAs="String">
<value>White</value>
</setting>
<setting name="TextColor" serializeAs="String">
<value>Black</value>
</setting>
</DevelopmentEnvironmentManager.WPF.Properties.Settings>
</applicationSettings>
</configuration>
NOTE: Replace 'DevelopmentEnvironmentManager.WPF' with the name of your application.
Additionally, you can go to Properies of the project and add Settings.Designer:
this will add convenient designer to your project, so you don't have to edit XML manually:
To access settings from the code - simply save and close all config editors, build app and access static Propeties (again, do not forget to change app name in the namespace):
string databasePath = DevelopmentEnvironmentManager.WPF.Properties.Settings.Default.SqliteDbFilePath;
I have a Class Library WPF Project, and I Use:
'Read Settings
Dim value as string = My.Settings.my_key
value = "new value"
'Write Settings
My.Settings.my_key = value
My.Settings.Save()

Categories