c# - 如何在 .NET Core 中使用 DateTime.ToString() 修复“缺少委托编组数据”错误?
问题描述
我编写了这个程序以最小化错误重现:
using System;
namespace HelloDates
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
var today = DateTime.Today;
Console.WriteLine("I know what day it is!");
string today_fmt = today.ToString("MM/dd/yyyy");
Console.WriteLine($"Today is {today_fmt}.");
}
}
}
添加了Microsoft.DotNet.ILCompiler,用CoreRT发布,运行,得到了这个结果:
Hello World!
I know what day it is!
Unhandled Exception: EETypeRva:0x00283B48: EETypeRva:0x00295C98 is missing delegate marshalling data. To enable delegate marshalling data, add a MarshalDelegate directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965
at HelloDates!<BaseAddress>+0x5fed
at HelloDates!<BaseAddress>+0xfddcf
at HelloDates!<BaseAddress>+0x1458fb
at System.Runtime.CompilerServices.ConditionalWeakTable`2.GetValue(TKey, ConditionalWeakTable`2.CreateValueCallback) + 0x3d
at System.Runtime.InteropServices.PInvokeMarshal.GetFunctionPointerForDelegate(Delegate) + 0x83
at HelloDates!<BaseAddress>+0xb6c38
at HelloDates!<BaseAddress>+0xb9ab8
at System.Globalization.DateTimeFormatInfo.set_Calendar(Calendar) + 0x94
at System.Globalization.CultureInfo.get_DateTimeFormat() + 0x57
at System.Globalization.CultureInfo.GetFormat(Type) + 0x88
at System.Globalization.DateTimeFormatInfo.get_CurrentInfo() + 0x50
at System.Globalization.DateTimeFormatInfo.GetInstance(IFormatProvider) + 0x8b
at HelloDates!<BaseAddress>+0x9b630
at HelloDates!<BaseAddress>+0x9b4bd
at HelloDates.Program.Main(String[]) + 0x62
at HelloDates!<BaseAddress>+0x155416
显然,当程序尝试格式化日期时会出现错误。但是我不知道委托编组数据或 EETypeRva 是什么,我在任何可以看到的地方都没有 rd.xml 文件,也无法理解链接的文档。关于反射的东西?
尤其令人沮丧的是,在我最初遇到错误的程序的早期版本中,ToString() 工作得很好,甚至可以编译为本机代码,我不知道可能发生了什么变化。
解决方案
推荐阅读
- r - R studio:使用 pivot_wider 旋转一列并重新格式化剩余的列
- python-3.x - 如何在 Python 中编码以获取给定两个数字的比率 (x:y) 格式或给定两个数字的百分比
- html - 我的外部 CSS 没有影响到我的 index.html
- python - For 循环不会嵌套
- node.js - 快速路线返回 200 总是带有一个空对象
- ms-word - 如何在 Web 响应中将 Word 邮件标签发送到浏览器
- javascript - 每当我在订阅功能下连接到 Mosquitto MQTT 时被授予为空
- python - 如何在基类中打印父类的实例?
- ios - 如果我从 AppStore 安装并重新安装应用程序,identifierForVendor 会发生变化吗?
- scala - Scala中的Spark数据框列操作