我的 .net 4.5.1
WPF 应用程序需要长路径支持。
App.config
中的此设置有效(支持长路径):
<runtime>
<AppContextSwitchOverrides value="Switch.System.IO.UseLegacyPathHandling=false;Switch.System.IO.BlockLongPaths=false" />
</runtime>
所以我尝试在代码中设置,但它不会改变行为:
public App()
{
// returns correct type:
Type type = Type.GetType("System.AppContext");
if (type != null)
{
// returns correct switch:
MethodInfo setSwitch = type.GetMethod("SetSwitch", BindingFlags.Public | BindingFlags.Static);
setSwitch.Invoke(null, new object[] { "Switch.System.IO.UseLegacyPathHandling", false });
setSwitch.Invoke(null, new object[] { "Switch.System.IO.BlockLongPaths", false });
}
}
.net 4.5.1 不支持“代码隐藏设置”吗?
最佳答案
Is that "code behind setting" not supported in .net 4.5.1?
不,不是。您应该使用AppContext.SetSwitch以编程方式设置开关,但由于此 API 是在 .NET Framework 4.6 中引入的,因此在早期版本上设置开关的唯一官方支持的方法是使用 App.config
文件。
关于c# - .net 4.5.1 不支持在代码后面写入 "System.AppContext"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66339560/