TL; DR; 编辑6:我缩小了它并提供了5个步骤来重现问题/错误.
public class Program
{
static void Main(string[] args)
{
}
public int Add(int a, int b)
{
return a + b;
}
}
}
Run Code Online (Sandbox Code Playgroud)
AddMethod并选择Create Unit Test:
[TestMethod()]
public void AddTest()
{
Program p = new Program();
var r = p.Add(1, 2);
Assert.IsTrue(3 == r);
}
Run Code Online (Sandbox Code Playgroud)
AddTest()> Live Testing> Include上的上下文菜单现在将Add的+符号更改为-
Live Unit Testing工作,将-符号改 回+,Live Test通过!!
现在添加对Nuget DLL的引用(任何人都可以) …
我有问题.我需要在.Net Core(C#)中编写一个使用app.config的程序,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="custom" type="ConfigurationSample.CustomConfigurationSection, ConfigurationSample"/>
</configSections>
<connectionStrings>
<add name="sampleDatabase" connectionString="Data Source=localhost\SQLExpress;Initial Catalog=SampleDatabase;Integrated Security=True"/>
</connectionStrings>
<appSettings>
<add key="sampleApplication" value="Configuration Sample"/>
</appSettings>
<custom>
<customConfigurations>
<add key="customSample" name="Mickey Mouse" age="83"/>
</customConfigurations>
</custom>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我写道:
string connectionString = ConfigurationManager.ConnectionStrings["sampleDatabase"].ConnectionString;
Console.WriteLine(connectionString);
// read appSettings configuration
string appSettingValue = ConfigurationManager.AppSettings["sampleApplication"];
Console.WriteLine(appSettingValue);
Run Code Online (Sandbox Code Playgroud)
它是来自互联网的例子,所以我认为会工作,但我得到例外:
System.Configuration.ConfigurationErrorsException: 'Error Initializing the configuration system.'
Inner Exception
TypeLoadException: Could not load type 'System.Configuration.InternalConfigurationHost' from assembly 'CoreCompat.System.Configuration, Version=4.2.3.0, Culture=neutral, PublicKeyToken=null' because the method 'get_bundled_machine_config' has no implementation …Run Code Online (Sandbox Code Playgroud) 在我的winform应用程序中,我正在尝试添加userSetting,尽管appSettings也出现了错误.当添加设置时,我得到一个抛出的异常,说:"配置系统无法初始化",内部异常"无法识别的配置部分userSetting"
例外细节:
System.Configuration.ConfigurationErrorsException was unhandled
Message="Configuration system failed to initialize"
Source="System.Configuration"
BareMessage="Configuration system failed to initialize"
Line=0
StackTrace:
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.RefreshSection(String sectionName)
at System.Configuration.ClientSettingsStore.ReadSettings(String sectionName, Boolean isUserScoped)
at System.Configuration.LocalFileSettingsProvider.GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties)
at System.Configuration.SettingsBase.GetPropertiesFromProvider(SettingsProvider provider)
at System.Configuration.SettingsBase.GetPropertyValueByName(String propertyName)
at System.Configuration.SettingsBase.get_Item(String propertyName)
at System.Configuration.ApplicationSettingsBase.GetPropertyValue(String propertyName)
at System.Configuration.ApplicationSettingsBase.get_Item(String propertyName)
at Settings.get_ApplicationData() in \Properties\Settings.Designer.cs:line 41
at Common.Initialize.IsSettingsInitialized()
at SurveyClient.Program.Main()
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object …Run Code Online (Sandbox Code Playgroud) 我有一个用C#编写的.net 4.0下的控制台应用程序它有一堆变量,我想进入App.Config(所以它将在一个地方).将此部分代码添加到App.Config(配置标记之间):
<configuration>
<appSettings>
<add key="RemoteDirectory" value="Some Text Here"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在我的程序中尝试使用此代码进行测试
Console.WriteLine(ConfigurationManager.AppSettings["RemoteDirectory"]);
Run Code Online (Sandbox Code Playgroud)
但我一直得到"配置系统初始化失败"的错误.
我在窗口应用程序中从app_config读取连接字符串时收到此异常"配置系统无法初始化"
string con = ConfigurationSettings.AppSettings["ConnectionString"].ToString();
Run Code Online (Sandbox Code Playgroud)
输入以下行后在此行上
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
Run Code Online (Sandbox Code Playgroud)
在AssemblyInfo.cs中.如果我从Assemblyinfo.cs中删除这一行,那么我没有异常我添加此程序集用于记录目的
此刻有些慌张。我正在尝试为客户安装软件更新,但不知何故我的 WCF 服务失败并给我一条我以前从未见过的错误消息。有没有人有任何想法?
日志名称:应用程序 来源:.NET 运行时 日期:2014-01-03 16:03:36 事件 ID:1026 任务类别:无 级别:错误 关键词:经典 用户:不适用 计算机:SERVER.NM.LOCAL 描述: 应用程序:MyApp.Web.Trading.WindowsServiceHost.exe 框架版本:v4.0.30319 描述:进程因未处理的异常而终止。 异常信息:System.Configuration.ConfigurationErrorsException 堆: 在 System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef) 在 System.Configuration.BaseConfigurationRecord.GetSection(System.String) 在 System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String) 在 System.Configuration.ConfigurationManager.GetSection(System.String) 在 System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetSectionFromConfigurationManager(System.String) 在 System.ServiceModel.Activation.AspNetEnvironment.UnsafeGetConfigurationSection(System.String) 在 System.ServiceModel.Configuration.ConfigurationHelpers.UnsafeGetAssociatedSection(System.Configuration.ContextInformation, System.String) 在 System.ServiceModel.Description.ConfigLoader.LookupService(System.String) 在 System.ServiceModel.ServiceHostBase.ApplyConfiguration() 在 System.ServiceModel.ServiceHostBase.InitializeDescription(System.ServiceModel.UriSchemeKeyedCollection) 在 System.ServiceModel.ServiceHost.InitializeDescription(System.Type, System.ServiceModel.UriSchemeKeyedCollection) 在 System.ServiceModel.ServiceHost..ctor(System.Type, System.Uri[]) 在 MyApp.Web.Trading.ServiceImplementations.Wcf.Start() 在 System.Threading.ThreadHelper.ThreadStart_Context(System.Object) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 在 System.Threading.ThreadHelper.ThreadStart()
.net ×4
c# ×4
app-config ×2
.net-3.5 ×1
.net-4.0 ×1
.net-core ×1
log4net ×1
settings ×1
unit-testing ×1
wcf ×1