Enyim Memcached issue over .Net MVC 3 - c#

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"

Related

How to use Service Principal/Managed Identity to access Azure App Configuration?

I need to disable Local Authentication Methods (Access Keys) for Azure App Configuration Stores.
Currently for an ASP.NET Framework application, I am using the following for accessing the App Configuration Store from my application:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="MyConfigStore" mode="Greedy" connectionString="${ConnectionString}" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
<add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
</builders>
</configBuilders>
Here the value of ${ConnectionString} = "Endpoint=https://<app_config>.azconfig.io;Id=<Id>;Secret=<Access Key>"
Now in order to access the App Configuration through the ASP.NET application, I created a Service Principal, generated a secret to use.
I have stored the CLIENT_ID, TENANT_ID and CLIENT_SECRET values. I have also assigned the App Configuration Data Reader role to the Service Principal.
I also have a managed identity which I can use.
Now what change do I need to make at the application side in order to access the App Configuration through the ASP.NET application?
You should use the endpoint instead of the connectionString parameter when you config your builders. This will tell the system to use the DefaultAzureCredential to connect to Azure App Configuration.
I would also put the "Environment" builder before the "AzureAppConfig" builder, so environment variables are available to the AppConfig builder during loading. It looks something like this:
<configBuilders>
<builders>
<add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
<add name="AzureAppConfig" mode="Greedy" endpoint="https://<AppConfigName>.azconfig.io" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
</builders>
</configBuilders>
Given you want to use the service principal, you should make CLIENT_ID, TENANT_ID and CLIENT_SECRET available as environment variables, so the DefaultAzureCredential will pick them up automatically.
You should NEVER put any secrets in the web.config file. You can find more information about the App Configuration builder library from the link below.
https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#azureappconfigurationbuilder
Check the below Workaround to access the App Configuration in the .NET Framework Application.
In Azure Portal => App Configuration => Configuration explorer,
create new Key-value.
Install the below NuGet Packages
Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguratio - Version 1.0.0
Microsoft.Configuration.ConfigurationBuilders.Environment - Version 2.0.0
System.Configuration.ConfigurationManager - Version 7.0.0
Configuration Section from my Web.config file:
<configSections>
<section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>
<configBuilders>
<builders>
<add name="AzureAppConfig" mode="Greedy" connectionString="Endpoint=https://AppConfigName.azconfig.io;Id=XqdS-l2-s0:****/;Secret=****" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
<add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
</builders>
</configBuilders>
<appSettings configBuilders="Environment,AzureAppConfig">
<add key="AppName" value=".NET Framework Sample" />
</appSettings>
Reading Config Value:
In Controller,
public ActionResult Index()
{
string FromAppConfig = System.Configuration.ConfigurationManager.AppSettings["TestApp:Settings:Message"];
string FromWebConfig = System.Configuration.ConfigurationManager.AppSettings["AppName"];
ViewBag.FromAppConfig = FromAppConfig;
ViewBag.FromWebConfig = FromWebConfig;
return View();
}
In View.cshtml:
#{
ViewBag.Title = "Home Page";
}
<div>
<h2> Value from App Configuration - #ViewBag.FromAppConfig</h2>
<h2> Value from Web.Config File - #ViewBag.FromWebConfig</h2>
</div>
OutPut:
References taken from MSDoc

Error in Early Bound Class in Dynamics CRM 2015

We are using CRM 2015 on-premise, we are trying to build customer portal, for that we generated Early Bound class
It is successfully generated and added to VS 2012. Now the problem is when i build the project in VS it goes fine and when i run the project it throws error in the Auto generated code
The code is below
public XrmServiceContext()
{
}
Below is my web.config code
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="Microsoft.Xrm.Client" type="Microsoft.Xrm.Client.Configuration.CrmSection, Microsoft.Xrm.Client"/>
</configSections>
<connectionStrings>
<add name="Xrm" connectionString="ServiceUri=http://Contoso/XRMServices/2011/OrganizationData.svc/; Domain=MyDomain; Username=vsaravanakumar; Password=Password#5"/>
</connectionStrings>
<Microsoft.Xrm.Client>
<contexts>
<add name="Xrm" type="Xrm.XrmServiceContext, WebAppWalkthrough"/>
</contexts>
</Microsoft.Xrm.Client>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID">
<controls>
<add tagPrefix="crm" namespace="Microsoft.Xrm.Portal.Web.UI.WebControls" assembly="Microsoft.Xrm.Portal"/>
</controls>
</pages>
<authentication mode="None"/>
</system.web>
</configuration>
The exception im getting is "Unable to find connection string with name".
I got this error during debugging of my code
I followed each and every steps what MSDN website is mentioned in the website portal development, if i missed anything please help me to resolve this error
Below is my Web.config Code
You need to define the CRM connection string in your app.config/web.config files. If you don't specify a connection string the Client DLL defaults to using the Config file.
The CRMSvcUtil.exe is used to generate a set of classes that you can include in your project and then use to read and manipulate CRM data. But they don't "do" anything until you create a connection and then instantiate and use them. The simplified connection string method is covered here...
https://msdn.microsoft.com/en-us/library/gg695810.aspx
Essentially you put a conn string in web.config section like this...
<add connectionString="Url=http://crm.contoso.com/xrmContoso; Domain=CONTOSO; Username=jsmith; Password=passcode" name="Crm" />
Then somewhere before you use early or late bound objects, you do this...
//Use the Microsoft Dynamics CRM Online connection string from the web.config (or app.config) file named "CRM".
var connection = new CrmConnection("CRM");
var service = new OrganizationService(connection);
var context = new CrmOrganizationServiceContext(connection);
With early bound you then can do a LINQ query against the generated code objects or {entity}Sets of the context like this...
var contacts = (from c in context.ContactSet
where c.LastName == "Smith"
select c);
This will return a collection of records matching your criteria that you could enumerate through with a foreach loop, or bind to a control, or send as a jSON array, or whatever you'd like.

Padarn OpenNetCF System.Argument.Exception when starting the server

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.

LocalDB 2012 Application not working with Framework 4.0.3 but works on 4.5

Initially I developed an application (winforms/c#) using VS 2013: framework 4.5, SQL Server 2012 and EntityFramework 6, but due a change on the user clients requirements and scenario, the application was migrated to: framework 4.0.3, LocalDB 2012 and EntityFramework 6.
To migrate projects frameworks I just change the targeted version, re-installed references (EntityFramework included) and checked the app.config.
And to migrate mdfs, in VS, created a Data Connection, using SQL Server DataProvider, ServerName (LocalDB)\v11.0, WindowsAuthentication and Attached the database file, that showed me a warning that it will be affecting the database, and then the connection was created, this connection was used to create the ADO Entity Data Models.
To deploy on clients I used a WIX project.
When I deploy on a machine that has the Framework 4.0.3 installed, the application crashes with the error:
"Underlying provider failed on open" and the innerexception was "A network-related or instance-specific occurred while establishing ..."
on
using (var dbContext = new SEDGRAICEntities()) <<-- Crashes Here
{
try
{
var baseubigeo = (from u in dbContext.T_MAE_UBIGEOCCPP
select u.id_departamento.Trim() + u.id_provincia.Trim() + u.id_distrito.Trim() + u.id_centropoblado.Trim()).ToList();
var query = from x in baselocalcp
where !baseubigeo.Contains(x)
select x;
result = query.AsEnumerable<string>().ToList();
}
catch (DbEntityValidationException dbEEx)
{
dbContext.Database.Connection.Close();
dbContext.Dispose();
throw dbEEx;
}
catch (Exception Ex)
{
dbContext.Database.Connection.Close();
dbContext.Dispose();
throw Ex;
}
}
SEDGRAICEntities:
public partial class SEDGRAICEntities : DbContext
{
public SEDGRAICEntities()
: base("name=SEDGRAICEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<DIS2K06> DIS2K06 { get; set; }
public virtual DbSet<T_MAE_UBIGEOCCPP> T_MAE_UBIGEOCCPP { get; set; }
public virtual DbSet<T_SEDD_GEOLOCALIZACIONCCPP> T_SEDD_GEOLOCALIZACIONCCPP { get; set; }
public virtual ObjectResult<UbigeoValidacion> sp_ValidaUbigeoWGS84(string p_ver, string p_xmlData, Nullable<bool> p_boolGeo)
{
var p_verParameter = p_ver != null ?
new ObjectParameter("p_ver", p_ver) :
new ObjectParameter("p_ver", typeof(string));
var p_xmlDataParameter = p_xmlData != null ?
new ObjectParameter("p_xmlData", p_xmlData) :
new ObjectParameter("p_xmlData", typeof(string));
var p_boolGeoParameter = p_boolGeo.HasValue ?
new ObjectParameter("p_boolGeo", p_boolGeo) :
new ObjectParameter("p_boolGeo", typeof(bool));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<UbigeoValidacion>("sp_ValidaUbigeoWGS84", p_verParameter, p_xmlDataParameter, p_boolGeoParameter);
}
}
The SEDGRAICEntities connectionstring on App.Config is:
<?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>
<appSettings>
<add key="BusinessID" value="20102010201" />
<add key="BusinessName" value="TESTBUSINESS" />
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<connectionStrings>
<add name="SEDGRAICCUADROSEntities" connectionString="metadata=res://*/erCUADROSmodel.csdl|res://*/erCUADROSmodel.ssdl|res://*/erCUADROSmodel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="SEDGRAICEntities" connectionString="metadata=res://*/erSEDGRAICmodel.csdl|res://*/erSEDGRAICmodel.ssdl|res://*/erSEDGRAICmodel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\SEDGRAIC.mdf;integrated security=true;connect timeout=60;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<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" />
</providers>
</entityFramework>
</configuration>
The thing is when I deploy the exact same installer on a machine with framework 4.5, and the app works perfectly.
I re-created the solution using VS 2010 with framework 4.0.3, with the same results.
The requirement it's to maintain framework 4.0.3, in order to keep compatibility with the clients machines, so I can't use framework 4.5.
I don't understand why the application needs framework 4.5 to work if I removed all (I think) dependencies and even recreated the solution.
Please help me with this.
Omar
Thanks to ErikEJ, I found a solution:
The standalone installer of the framework 4 did not contain the update necessary to support LocalDB (even though the version on the registry [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full] says 4.0.30319)
Basically, the framework needs the 4.0.2 version of the framework to be installed. One can be misleading thinking that we have a greater version, but actually, we don't.
So, thanks to ErikEJ, find that we have a more compelling way to find the correct version actually is described here: How can I find out if .NET 4.02 is installed?.
I only had 2 registry keys instead of the 6 in total that we need.
So we have to install the update to 4.0.2 (KB2544514) to get them. Once installed, now we have the 6 keys needed to use safely a LocalDB database.
Omar

Strange exception coming out of OdbcConnection.Open()

Bashing our heads against the wall here
We are an ISV and have hundreds of companies using our software with no problems. The software is Winforms/C# on .NET 2.0.
One of our clients has installed our software and it crashes on startup on all of their machines, apart from on one guy's laptop where it works fine.
On calling OdbcConnection.Open(), we get the following exception:
The type initializer for 'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.
at System.Transactions.Diagnostics.DiagnosticTrace.get_Verbose()
at System.Transactions.Transaction.get_Current()
at System.Data.Common.ADP.IsSysTxEqualSysEsTransaction()
at System.Data.Common.ADP.NeedManualEnlistment()
at System.Data.Odbc.OdbcConnection.Open()
at OurCompany.OurForm.connectionTestWorker_DoWork(Object sender)
This has an InnerException:
Configuration system failed to initialize
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
Google just says "app.config is syntactically incorrect, rebuild it" yet the same app.config works fine on hundreds of other machines.
Here's app.config, as requested:
<?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="OurApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<system.diagnostics>
</system.diagnostics>
<applicationSettings>
<OurApp.Properties.Settings>
<setting name="OurApp_WebServices_OurServiceName" serializeAs="String">
<value>http://ourdomain.com/OurService.asmx</value>
</setting>
</OurApp.Properties.Settings>
</applicationSettings>
<appSettings>
<add key="WorkflowEngine" value="old" />
<add key="ProductID" value="3" />
<add key="EnableMigrationWizard" value="false" />
<add key="UseAlternativeFtpPort" value="true" />
<add key="FeedbackWhileConnecting" value="true" />
</appSettings>
</configuration>
A repair of the .NET Framework hasn't fixed this. I'm at a total loss. Any ideas?
Check machine.config and user.config. Along with app.config, those are the 3 that make up the config sections.
Reflector shows EnsureInit has 2 exception paths:
catch (Exception exception) {
this._initError = new ConfigurationErrorsException(SR.GetString("Config_client_config_init_error"), exception);
throw this._initError;
} catch {
this._initError = new ConfigurationErrorsException(SR.GetString("Config_client_config_init_error"));
throw this._initError;
}
Since the 2nd would only handle a non-CLS exception, I'd guess that you're hitting the first one. If that's the case, you probably need to recursively go through InnerException to get the full details.
Just for anyone's future reference, I had this problem with a local app that I was developing on my desktop and found that the problem was simply that I had the case wrong in . Once that was fixed it worked like a charm again.
Solved this by overwriting machine.config with a known working copy from another machine at the same SP/patch level.
I had this exact same error occur when trying to open an OLE DB connection with ASP/VB.NET 3.5 SP1. If I add my URL to the list of trusted sites in IE, then the error goes away and the connection opens successfully. I don't know if this will fix things in other browsers.

Categories