嘗試通過連接到 ServiceStack 中的 db 來構建集成測驗。我的 ServiceStack 應用程式運行良好,但是當我運行簡單測驗時,我在第 22 行收到了此錯誤訊息
System.MissingMethodException: '方法未找到:'Int32 ServiceStack.DataAnnotations.CustomFieldAttribute.get_Order()'。'
有一個精簡版的鱈魚:
using ServiceStack;
using ServiceStack.OrmLite;
using ServiceStack.Data;
using NUnit.Framework;
using ServiceStack.DataAnnotations;
using System.Collections.Generic;
namespace oth.Tests.IntegrationTests
{
public class AppHost2 : AppSelfHostBase
{
public AppHost2() : base("Customer REST Example", typeof(CustomerService).Assembly) { }
public override void Configure(Container container)
{
var connectionString = "Host=localhost;Port=5432;Database=test_1234;Username=postgres;Password=local";
container.Register<IDbConnectionFactory>(c =>
new OrmLiteConnectionFactory(connectionString, PostgreSqlDialect.Provider));
using var db = container.Resolve<IDbConnectionFactory>().Open();
db.CreateTableIfNotExists<Customer>();
}
}
public class Customer
{
[AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}
[Route("/customers", "GET")]
public class GetCustomers : IReturn<GetCustomersResponse> { }
public class GetCustomersResponse
{
public List<Customer> Results { get; set; }
}
public class CustomerService : Service
{
public object Get(GetCustomers request)
{
return new GetCustomersResponse { Results = Db.Select<Customer>() };
}
}
public class CustomerRestExample
{
const string BaseUri = "http://localhost:2000/";
ServiceStackHost appHost;
public CustomerRestExample()
{
//Start your AppHost on TestFixture SetUp
appHost = new AppHost2()
.Init()
.Start(BaseUri);
}
[OneTimeTearDown]
public void OneTimeTearDown() => appHost.Dispose();
/* Write your Integration Tests against the self-host instance */
[Test]
public void Run_Customer_REST_Example()
{
var client = new JsonServiceClient(BaseUri);
var all = client.Get(new GetCustomers());
Assert.That(all.Results.Count, Is.EqualTo(0));
}
}
}
uj5u.com熱心網友回復:
任何時候在使用MyGet 預發布包時看到缺少型別或缺少方法例外,都意味著您有一個臟安裝(即使用來自不同構建時間的預發布包)。
在這種情況下,您需要清除 Nuget 包快取并再次下載最新的包,以確保所有包都來自最新的相同版本:
$ dotnet nuget locals all -clear
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391479.html
標籤:C# PostgreSQL的 服务栈 ormlite-servicestack
