小编Joe*_*Fan的帖子

无法强制转换为我的自定义ConfigurationSection

我正在尝试读取这样的配置文件:

var dllPath =  System.IO.Path.GetDirectoryName(System.Reflection.Assembly.
    GetExecutingAssembly().GetName().CodeBase);
dllPath = dllPath.Replace("file:\\", string.Empty);
var configPath = string.Format(@"{0}\..\contentFolders.config", dllPath);
var fileMap = new ExeConfigurationFileMap() {ExeConfigFilename = configPath};
var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, 
    ConfigurationUserLevel.None);
var contentFolderConfig = 
    (ContentFolderSettings)config.GetSection("contentFolderConfiguration");
Run Code Online (Sandbox Code Playgroud)

ContentFolderSettingsCorp.Common项目中定义了它继承自ConfigurationSection.这是以下内容contentFolders.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <section name="contentFolderConfiguration"
    type="Corp.Common.ContentFolderSettings, Corp.Common"
    requirePermission="false"/>
  <contentFolderConfiguration>
    <contentFolders>
      <contentFolder key="ImagesFolder" path="content\images"/>
      <contentFolder key="CssFolder" path="content\css"/>
      ...
    </contentFolders>
  </contentFolderConfiguration>
</configuration>
Run Code Online (Sandbox Code Playgroud)

但线路呼叫config.GetSection()正在投入InvalidCastException:

Unable to cast object of type 'System.Configuration.DefaultSection' to type 
'Corp.Common.ContentFolderSettings'.
Run Code Online (Sandbox Code Playgroud)

.net c# configuration-files

3
推荐指数
1
解决办法
4458
查看次数

应该枚举包含无吗?

我有时看到过enum这样的事情:

public enum Color {
    None, Black, Red, Blue
}
Run Code Online (Sandbox Code Playgroud)

代码如下:

Color color;

...

if (color == Color.None) ...
Run Code Online (Sandbox Code Playgroud)

我更喜欢使用可以为空的枚举并像这样编码:

public enum Color {
    Black, Red, Blue
}

...

Color? color;

...

if (color == null) ...
Run Code Online (Sandbox Code Playgroud)

哪种款式首选?

c# enums coding-style

3
推荐指数
1
解决办法
671
查看次数

如何修复“exec 用户进程导致没有这样的文件或目录”

我正在尝试tini在我的 Dockerfile 中使用,但出现错误。

我使用了tini自述文件中的代码示例。

# ... code which builds /app/foo

# Add Tini
ENV TINI_VERSION v0.18.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini
ENTRYPOINT ["/tini", "--"]

# Run the program when the container starts
CMD ["/app/foo"]
Run Code Online (Sandbox Code Playgroud)

我希望我的程序可以在没有运行的情况下运行,PID=1但我得到:standard_init_linux.go:207: exec user process caused "no such file or directory"

编辑:

/app/foo在 Dockerfile 的开头创建。没有问题/app/foo。作为证明,如果我注释掉该ENTRYPOINT行(或删除所有tini相关代码),/app/foo除了它具有PID=1

docker

3
推荐指数
2
解决办法
7425
查看次数

无法将默认比较器作为IComparer <object>传递

我试图IComparer<object>使用代码调用一个期望参数类型的"排序"方法:

collection.Sort((IComparer<object>)Comparer<DateTime>.Default)
Run Code Online (Sandbox Code Playgroud)

它构建但在运行时我得到一个带有消息的InvalidCastException:

Unable to cast object of type
'System.Collections.Generic.GenericComparer`1[System.DateTime]'
to type 'System.Collections.Generic.IComparer`1[System.Object]'.
Run Code Online (Sandbox Code Playgroud)

怎么办?

c# generics llblgenpro

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

像List <string>但保持字符串有序吗?

我想要一个类似List <string>的东西,但每当我做一个"添加"时,它会保持列表的排序.有任何想法吗?

c# sorting list

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

在.NET中自动扩展数组?

.NET是否与Perl数组类似,它们以数字方式编制索引,但会根据需要自动扩展?它会像这样工作:

var x = new DreamArray<string>();

x[6] = "foo";  // x automatically has 7 elements
x[10] = "bar"; // now it has 11
Run Code Online (Sandbox Code Playgroud)

.net collections perl

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

为什么我的继续执行Perl 5.10中的下一个块?

当我运行这个:

use feature ':5.10';
$x=1;
given ($x) {
    when(1) {
        say '1';
        $x = 2;
        continue;
    }
    when (2) {
        say '2';
    }
}
Run Code Online (Sandbox Code Playgroud)

这应该打印1和2,但它只打印1.我错过了什么?

编辑:

我添加了$ x = 2,它仍然只打印"1"

perl continue switch-statement

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

让 Visual Studio 为相同的 C# 源代码生成相同的 DLL

我注意到,当我构建给定的 C# 或 VB.NET 源代码来生成 DLL 时,每次的二进制输出都不同。如果不是这种情况,这将对我们的构建/部署过程很有帮助。我能控制这个吗?

c# vb.net build visual-studio-2010 visual-studio

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

asp.net缓存问题

我看到一些使用浏览器缓存的静态页面的问题,这是不希望的。为了防止缓存,我正在设置

<clientCache cacheControlMode="DisableCache" />
Run Code Online (Sandbox Code Playgroud)

<location>在 web.config的相关标签中

如果我在 Firebug 中打开页面(在Net选项卡中),我会看到 Response 标头 Cache-Control: no-cache是正确的,但 Response 的状态是304 Not Modified!这不是矛盾吗?我怎样才能让它停止缓存(即总是发送一个 200 的内容)?

asp.net iis-7 caching

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

视觉工作室找对话框增长

我记得看到一篇关于如何修复Visual Studio 2010错误的博客文章,每当你提起它时,查找对话框的宽度会增加,但是我没有绕过它,现在我不记得我在哪里看到了它.有谁有这个链接?

visual-studio-2010

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