我想将图像保存到我的mysql数据库中。
这是我的代码:
课程:
public async void SIE()
{
TrialClass trialClass = new TrialClass(ImagesPaths1);
BlogRestClient<TrialClass> restClient = new BlogRestClient<TrialClass>();
await restClient.PostAsync(trialClass);
}
public class TrialClass
{
public List<ImageFormatClass> ImagesPath2;
public TrialClass(List<ImageFormatClass> imagespath)
{
ImagesPath2 = imagespath;
}
}
public class ImageFormatClass
{
public Image SavedImage;
public int Format;
public ImageFormatClass()
{
}
}
private void Post_Clicked(object sender, EventArgs e)
{
SIE();
}
Web API控制器:
public void Post([FromBody] TrialClass value)
{
foreach (ImageFormatClass s in value.ImagesPath2)
{
string sqlstring = "server=; port= ; user id =;Password=;Database=;";
MySqlConnection conn = new MySqlConnection(sqlstring);
try
{
conn.Open();
}
catch (MySqlException ex)
{
throw ex;
}
string Query = "INSERT INTO test.blogimagestable (ImagesId)values( ?str);";
MySqlCommand cmd = new MySqlCommand(Query, conn);
cmd.Parameters.Add("?str", MySqlDbType.VarString, 256).Value = s.SavedImage;
cmd.ExecuteReader();
conn.Close();
}
}
每当我按下发布按钮触发Post_Clicked
事件时,都会出现此错误
Newtonsoft.Json.JsonSerializationException:'为类型为'System.Reflection.RuntimeModule'的属性'ManifestModule'检测到自引用循环。路径“ ImagesPath2 [0] .SavedImage.Source.Stream.Method.Module.Assembly”。
在`await restClient.PostAsync(trialClass);