我正在关注 suave 教程,我正在努力将 JSON 返回到前端。我目前有代码。(我没有使用 Chiron 包)。我可以很好地启动 Web 服务器,但是当我转到 localhost:8083/hello 时,我收到下面发布的错误消息。我不确定如何进行调试,或者是什么原因造成的。
这是我正在关注的教程
#r "../packages/Suave/lib/net40/Suave.dll"
#r "System.Runtime.Serialization.dll"
#r "../packages/FParsec/lib/net40-client/FParsecCS.dll"
#r "../packages/Aether/lib/net35/Aether.dll"
#r "../packages/Chiron/lib/net40/Chiron.dll"
module Test =
open Suave // always open suave
open Suave.Successful // for OK-result
open Suave.Web // for config
open Suave.Operators
open Suave.Http
open Suave.Filters
open Suave.Json
open System.Runtime.Serialization
open Suave.Writers
[<DataContract>]
type Foo =
{
[<field: DataMember(Name = "foo")>]
foo : string;
}
[<DataContract>]
type Bar =
{
[<field: DataMember(Name = "bar")>]
bar : string;
}
let router =
choose
[path "/hello" >=> (mapJson (fun (a:Foo) -> { bar = a.foo })) >=> setMimeType "application/json; charset=utf-8";
path "/bye" >=> OK "GOOD WHAT"]
startWebServer defaultConfig router
派生类必须实现它
System.NotImplementedException:派生类必须在 System.Reflection.Module.GetCustomAttributes (System.Type attributeType, Boolean inherit) <0x104618170 + 0x00010> in :0 at System.Reflection.Emit.ModuleBuilder.GetCustomAttributes (System.Type attributeType,布尔继承)<0x1045f1800 + 0x0001b> 在 System.Runtime.Serialization.DataContract.GetGlobalDataContractNamespace 的 0 处(System.String clrNs,ICustomAttributeProvider customAttribuetProvider)<0x10da40f60 + 0x00045> 在 System.Runtime.Serialization.DataContract.GetDefaultDataContractNamespace 的 0 处(System .Type 类型)<0x10da40e80 + 0x00051> in :0 在 System.Runtime.Serialization.DataContract.GetDCTypeStableName(System.Type 类型,System.Runtime.Serialization.DataContractAttribute dataContractAttribute)<0x10da3fd50 + 0x000f5> in :0 在 System.Runtime.Serialization.DataContract.GetStableName(System.Type 类型,System.Collections.Generic.Dictionary
2 previousCollectionTypes, System.Boolean& hasDataContract) <0x10da3f570 + 0x00092> in :0 at System.Runtime.Serialization.DataContract.GetStableName (System.Type type, System.Boolean& hasDataContract) <0x10da3f4f0 + 0x00058> in :0 at System.Runtime.Serialization.ClassDataContract+ClassDataContractCriticalHelper.GetStableNameAndSetHasDataContract (System.Type type) <0x10da3f490 + 0x00031> in :0 at System.Runtime.Serialization.ClassDataContract+ClassDataContractCriticalHelper..ctor (System.Type type) <0x10da3e1e0 + 0x00044> in :0 at System.Runtime.Serialization.ClassDataContract..ctor (System.Type type) <0x10da3e120 + 0x00045> in :0 at System.Runtime.Serialization.DataContract+DataContractCriticalHelper.CreateDataContract (Int32 id, RuntimeTypeHandle typeHandle, System.Type type) <0x10da3ab00 + 0x0031e> in :0 at System.Runtime.Serialization.DataContract+DataContractCriticalHelper.GetDataContractSkipValidation (Int32 id, RuntimeTypeHandle typeHandle, System.Type type) <0x10da3aa50 + 0x0005c> in :0 at System.Runtime.Serialization.DataContract.GetDataContractSkipValidation (Int32 id, RuntimeTypeHandle typeHandle, System.Type type) <0x10da3aa10 + 0x00023> in :0 at System.Runtime.Serialization.DataContract.GetDataContract (Int32 id, RuntimeTypeHandle typeHandle, SerializationMode mode) <0x10da3a9c0 + 0x00025> in :0 at System.Runtime.Serialization.DataContract.GetDataContract (RuntimeTypeHandle typeHandle, System.Type type, SerializationMode mode) <0x10da3a240 + 0x00036> in :0 at System.Runtime.Serialization.DataContract.GetDataContract (System.Type type) <0x10da3a1f0 + 0x0002f> in :0 at System.Runtime.Serialization.Json.DataContractJsonSerializer.get_RootContract () <0x10da3a0f0 + 0x0005b> in :0 at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalIsStartObject (System.Runtime.Serialization.XmlReaderDelegator reader) <0x10da39fa0 + 0x00038> in :0 at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject (System.Runtime.Serialization.XmlReaderDelegator xmlReader, Boolean verifyObjectName) <0x10da39b60 + 0x00046> in :0 at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject (System.Runtime.Serialization.XmlReaderDelegator reader, Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) <0x10da39b30 + 0x00020> in :0 at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, Boolean verifyObjectName, System.Runtime.Serialization.DataContractResolver dataContractResolver) <0x10da39760 + 0x0020f> in :0 at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions (System.Runtime.Serialization.XmlReaderDelegator reader, Boolean verifyObjectName) <0x10da396f0 + 0x00025> in :0 at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.Xml.XmlDictionaryReader reader) <0x10da39480 + 0x0006d> in :0 at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject (System.IO.Stream stream) <0x10da36030 + 0x0005c> in :0 at Suave.Json.fromJson[T] (System.Byte[] bytes) <0x10da35890 + 0x00103> in :0 at Suave.Json+mapJson@31[a,b].Invoke (Suave.HttpRequest r) <0x10da35740 + 0x0004f> in :0 at Microsoft.FSharp.Core.FSharpFunc
2[T,TResult].InvokeFast[V] (Microsoft.FSharp.Core.FSharpFunc2 func, Microsoft.FSharp.Core.T arg1, Microsoft.FSharp.Core.TResult arg2) <0x1052faeb0 + 0x000a1> in :0 at Suave.Json+mapJson@31-2.Invoke (Suave.HttpContext context) <0x10da356f0 + 0x00034> in :0 at Suave.WebPart+bind@14-5[a,b].Invoke (Microsoft.FSharp.Core.FSharpOption
1 _arg1) <0x10da331d0 + 0x0004c> 在 :0 在 Microsoft.FSharp.Control.AsyncBuilderImpl+args@835-1[a,b]。调用 (aa) <0x10d4db780 + 0x000af> in :0