相关疑难解决方法(0)

在运行时更改默认app.config

我有以下问题:
我们有一个加载模块的应用程序(添加).这些模块可能需要app.config中的条目(例如WCF配置).因为模块是动态加载的,所以我不希望在我的应用程序的app.config文件中包含这些条目.
我想做的是以下内容:

  • 在内存中创建一个新的app.config,它包含模块中的配置部分
  • 告诉我的应用程序使用新的app.config

注意:我不想覆盖默认的app.config!

它应该透明地工作,以便例如ConfigurationManager.AppSettings使用该新文件.

在我这个问题的评价,我用同样的解决方案提出了为这里提供:刷新的app.config与NUnit的.
不幸的是,它似乎没有做任何事情,因为我仍然从正常的app.config获取数据.

我用这段代码来测试它:

Console.WriteLine(ConfigurationManager.AppSettings["SettingA"]);
Console.WriteLine(Settings.Default.Setting);

var combinedConfig = string.Format(CONFIG2, CONFIG);
var tempFileName = Path.GetTempFileName();
using (var writer = new StreamWriter(tempFileName))
{
    writer.Write(combinedConfig);
}

using(AppConfig.Change(tempFileName))
{
    Console.WriteLine(ConfigurationManager.AppSettings["SettingA"]);
    Console.WriteLine(Settings.Default.Setting);
}
Run Code Online (Sandbox Code Playgroud)

它打印相同的值twices,虽然combinedConfig包含除正常app.config之外的其他值.

.net c# app-config

128
推荐指数
4
解决办法
8万
查看次数

如何创建F#WCF客户端?我一直收到app.config错误

我一直在用F#创建自托管应用服务器.我已经启动并运行了应用服务器,我可以使用C#客户端进行连接,但是使用F#可以更好地完成我想做的一些事情.问题是我似乎无法使F#客户端正常工作.我找到了一些例子,但我似乎无法让它们中的任何一个起作用.最有希望的是这里.在这个例子后,我想出了以下代码:

let address= new EndpointAddress("net.tcp://192.168.101.100:2009/PrevisionService/tcp")
let factory = new ChannelFactory<IPrevisionAppServer>("NetTcpBinding_IPrevisionAppServer", address)
let channel = factory.CreateChannel()//address)
let GetDataObject (sql) = channel.GetDataObject(sql)
factory.Close()
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

找不到名为"NetTcpBinding_IPrevisionAppServer"的端点元素,并在ServiceModel客户端配置部分中收缩"PrevisionAppServer.Main + IPrevisionAppServer".这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素.

我有一个app.config文件,它在C#中工作得很好:

<?xml version="1.0" encoding="utf-8"?>
<!--Client Config-->
<configuration>
  <system.serviceModel>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IPrevisionAppServer" closeTimeout="00:01:00"
          openTimeout="00:20:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
          hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647"
          maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647"
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647"
            maxBytesPerRead="2147483647"
            maxNameTableCharCount="2147483647" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address="net.tcp://192.168.101.100:2009/PrevisionService/tcp" behaviorConfiguration="ServiceViewEventBehavior"
          binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IPrevisionAppServer"
          contract="*" name="NetTcpBinding_IPrevisionAppServer">
      </endpoint>
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ServiceViewEventBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>`
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,它似乎忽略了app.config文件.有任何想法吗?是否有更好的代码来实现这一点?任何人将不胜感激!

更新 …

wcf f#

6
推荐指数
1
解决办法
1216
查看次数

使用fsx文件中的app.config

是否可以使用F#脚本(fsx)文件中的app.config文件?如果是这样,怎么样?我在哪里放置文件以及它将被称为什么?

configuration-files f#-scripting

6
推荐指数
1
解决办法
1052
查看次数

使用F#Script中的app.config

我在这里看到了几个关于堆栈溢出的相关问题,但是没有一个似乎有答案.我将提出问题,然后包括我找到的相关SO问题的链接.

我有一个用C#编写的核心域库,它利用了Entity Framework.因此,EF要求dbcontext将连接字符串传递给base(dbcontext).在我的情况下,连接字符串存在于app.config(或web.config)中,当然取决于顶级项目,名称是"AnnotatorModel".

我需要在我的F#脚本中实例化DBContext以测试一些查询和分析.

我已将此添加到我的F#项目中的app.config并尝试了一些关于SO的答案但没有成功.有没有人知道一个很容易直接的方法来实现这一目标?

这是代码,意识到它试图实例化dbcontext,AnnotatorModel.

let PredictBestEntities (number:int) (tokens:string seq) =
   let db = new AnnotatorModel()    
   tokens 
   |> Seq.map ...etc etc
Run Code Online (Sandbox Code Playgroud)

谢谢,〜大卫

相关问题:

从App.config F#AppSettings提供程序获取并使用连接字符串

App.config和F#Interactive无法正常工作

https://social.msdn.microsoft.com/Forums/vstudio/en-US/5b4dba22-28ec-4bbd-bc53-c5102d0b938f/using-fsi-and-an-appconfig?forum=fsharpgeneral

configuration f#

2
推荐指数
1
解决办法
854
查看次数