尝试使用Postman将一些数据发布到ms sql服务器并测试我的api。 我收到错误消息:
InvalidOperationException:无法解析类型的服务 “ Microsoft.AspNetCore.Identity.UserManager`1 [MyOrg.Models.User]”而 尝试激活“ MyOrg.Controllers.AccountsController”。
我已经检查并尝试了几种类似问题的解决方案,但无济于事。
这是我的代码:
Startup.cs
private String copyFiletoExternalStorage(int resourceId, String resourceName){
String pathSDCard = Environment.getExternalStorageDirectory() + "/Android/data/" + resourceName;
try{
InputStream in = getResources().openRawResource(resourceId);
FileOutputStream out = null;
out = new FileOutputStream(pathSDCard);
byte[] buff = new byte[1024];
int read = 0;
try {
while ((read = in.read(buff)) > 0) {
out.write(buff, 0, read);
}
} finally {
in.close();
out.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return pathSDCard;
}
private void shareFile(){
try {
String mediaPath = copyFiletoExternalStorage(R.raw.numer_1, "numer_1.mp3");
Intent shareMedia = new Intent(Intent.ACTION_SEND);
shareMedia.setPackage("com.facebook.orca");
shareMedia.setType("audio/mp3");
shareMedia.putExtra(Intent.EXTRA_STREAM, Uri.parse(mediaPath));
startActivity(Intent.createChooser(shareMedia, "Compartiendo archivo."));
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Messenger nie jest zainstalowany", Toast.LENGTH_LONG).show();
}
}
AccountsController.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly("MyOrg")));
}
我不确定是什么问题。您有任何解决办法的想法吗?