草庐IT

kotlinx.serialization

全部标签

c# - "Unable to cast object of type ' System.Net.Http.Formatting.JsonContractResolver ' to type ' Newtonsoft.Json.Serialization.DefaultContractResolver '."

我们有一个最近被转移到新服务器的WEBAPI项目。在对项目的有效负载进行一些添加后,我正在运行我的项目,但它突然抛出以下错误:Unabletocastobjectoftype'System.Net.Http.Formatting.JsonContractResolver'totype'Newtonsoft.Json.Serialization.DefaultContractResolver'.有问题的代码行在global.asax中:protectedvoidApplication_Start(){GlobalConfiguration.Configure(WebApiConfig.R

c# - 如何通过调用 XmlSerializer.Serialize 创建 XmlNode?

我正在使用一个类库,它在.xml中表示它的一些配置。使用XmlSerializer读取配置。幸运的是,代表.xml的类使用XmlAnyElement属性,我可以根据自己的目的扩展配置数据,而无需修改原始类库。ThisissomedataThisismydata这很适合反序列化。我能够允许类库像往常一样反序列化.xml,并且我可以使用我自己的XmlSerializer实例和XmlNodeReader针对内部XmlNode.publicclassConfig{[XmlElement]publicstringdata;[XmlAnyElement]publicXmlNodeelement;}

c# - Serial Port ReadLine vs ReadExisting 或如何从串口正确读取数据

我正在从串口读取数据。数据超出了规模。我现在正在使用Readline(),即使在我删除DiscardInBuffer()之后数据也会丢失。从串口读取数据的正确方法是什么?网上的例子太少了,我觉得这就像是无人问津的chalice。C#、WinCE5.0、HP瘦客户机、Compact框架2.0privatevoidWeighSample(){this._processingDone=false;this._workerThread=newThread(CaptureWeight);this._workerThread.IsBackground=true;this._workerThread

c# - ASP.net Web API : change class name when serializing

我有一个产品的数据传输对象类publicclassProductDTO{publicGuidId{get;set;}publicstringName{get;set;}//Otherproperties}当Asp.net序列化JSON(使用JSON.NET)或XML中的对象时,它会生成ProductDTO对象。但是,我想在序列化期间更改名称,从ProductDTO到Product,使用某种属性:[Name("Product")]publicclassProductDTO{[Name("ProductId")]publicGuidId{get;set;}publicstringName{

c# - Json Serialize Dictionary<Enum, Int32> 的问题

每当我尝试序列化字典时,我都会得到异常:System.ArgumentException:Type'System.Collections.Generic.Dictionary`2[[Foo.DictionarySerializationTest+TestEnum,Foo,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null],[System.Int32,mscorlib,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]]'isnotsupportedfors

c# - 串口通信 : polling serial port vs using serial port DataReceived event

我只是在回顾我在CF2.0上用C#编写的与串行端口通信的一些代码。我没有使用DataReceived事件,因为它不可靠。MSDNstatesthat:TheDataReceivedeventisnotgauranteedtoberaisedforeverybytereceived.UsetheBytesToReadpropertytodeterminehowmuchdataislefttobereadinthebuffer.我用read()轮询端口,并有一个委托(delegate)在读取数据时处理数据。我还在某处读到“轮询不好”(没有给出解释)。知道轮询为什么不好吗?除了通常的线程警告

c# - 具有内部属性的 JSON Serializer 对象

我有一些内部属性的类,我也想将它们序列化为json。我怎样才能做到这一点?例如publicclassFoo{internalintnum1{get;set;}internaldoublenum2{get;set;}publicstringDescription{get;set;}publicoverridestringToString(){if(!string.IsNullOrEmpty(Description))returnDescription;returnbase.ToString();}}使用保存Foof=newFoo();f.Description="FooExample";

c# - 如何在 C# 中执行 System.Web.Script.Serialization?

如何在C#现代UI中执行此操作?varurl="http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0";varwc=newWebClient();varrawFeedData=wc.DownloadString(url);//YoucanuseSystem.Web.Script.Serializationifyoudon'twanttouseJson.NETJavaScriptSerializerser=newJavaScriptSer

C# 和 .NET : How to serialize a structure into a byte[] array, 使用 BinaryWriter?

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭6年前。Improvethisquestion如何使用BinaryWriter将相当复杂的结构序列化为byte[]数组?更新:为此,每个结构(和子结构?)都必须用[Serializable]属性修饰。我不需要实现ISerializable接口(interface),因为它旨在让对象控制自己的序列化。

c# - SignalR 2.0 更改 Json Serializer 以支持派生类型对象

请注意,我在这里明确引用了SignalR2.0...我已经看到一些(令人讨厌的)方法用于SignalR1.1/1.2...但还没有用于2.0。有没有人成功更改SignalR2.0默认json序列化程序以启用派生类型的发送?根据我对SignalR2.0的了解,这应该是可能的,但是,我没有任何运气,也没有在任何地方找到完整的示例。我是这样开始的……如有任何帮助,我们将不胜感激。我的Startup.cs[assembly:OwinStartup(typeof(SignalRChat.Startup))]namespaceSignalRChat{publicclassStartup{publi