小编Har*_*rim的帖子

字典的序列化/反序列化不支持字典,键必须是字符串或对象

当我尝试在Ajax中反序列化此Dictionary时,我有这个方法将Dictionary作为JsonResult返回我收到此错误:

这是我在MVC中的方法:

[HttpPost]
public JsonResult GetCalculateAmortizationSchedule()
{
      var data =.....
      var httpClient = new HttpClient();
      var response = httpClient.PostAsJsonAsync("http://localhost:62815/v1/APR/CalculateAmortizationSchedule", data).Result;
      var returnValue = response.Content.ReadAsAsync<Dictionary<int, AmItem>>().Result;
      return Json(returnValue);
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

键入'System.Collections.Generic.Dictionary`2 [[System.Int32,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089],[ConnectionMappingSample.Models.AmItem,ConnectionMappingSample,Version = 1.0.0.0,Culture对于字典的序列化/反序列化,不支持= neutral,PublicKeyToken = null]]',键必须是字符串或对象.

.net c# serialization dictionary

10
推荐指数
1
解决办法
4708
查看次数

Powershell结果集未在C#中被提取

单击button1时,将执行以下代码,该代码将运行PowerShell脚本以获取当前的SQL Server实例.但是,运行此操作时,结果集(结果变量)的计数为PowerShell输出的0行.当我在本机PowerShell中运行相同的代码时,它显示3行实例名称.

任何人都可以建议我是否遗漏了什么?

private void button1_Click(object sender, EventArgs e)
{
    //If the logPath exists, delete the file
    string logPath = "Output.Log";
    if (File.Exists(logPath))
    {
        File.Delete(logPath);
    }
    string[] Servers = richTextBox1.Text.Split('\n');

    //Pass each server name from the listview to the 'Server' variable
    foreach (string Server in Servers)
    {
        //PowerShell Script
        string PSScript = @"
        param([Parameter(Mandatory = $true, ValueFromPipeline = $true)][string] $server)

        Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force;
        Import-Module SQLServer;
        Try 
        {
            Set-Location SQLServer:\\SQL\\$server -ErrorAction Stop; 
            Get-ChildItem | Select-Object -ExpandProperty Name;
        } …
Run Code Online (Sandbox Code Playgroud)

c# sql-server powershell winforms

6
推荐指数
1
解决办法
295
查看次数

如何将二进制字符串写入文件 C#

我有一个像 temp = "0101110011" 这样的二进制数字符串,我想将它保存为文件,这个临时文件有 10 个字符,我如何将此字符串保存到 10 位长度的文件?

void Save_Data(string temp)
{
    bool[] BoolArray = new bool[temp.Length];
    BitArray Barray = new BitArray(BoolArray.Length);
    char[] ch = temp.ToCharArray();

    for (int i = 0; i < temp.Length; i++)
    {
        if (ch[i] == '0')
        {
            Barray[i] = false;
        }
        else
        {
            Barray[i] = true;
        }
    }

    Stream stream = new FileStream("D:\\test.dat", FileMode.Create);
    StreamWriter sw = new StreamWriter(stream);

    foreach (bool bit in Barray)
    {
        sw.Write(bit ? 1 : 0);
    }

    sw.Flush();
    sw.Close();
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,我的文件长度为 …

c# bitarray binarywriter

5
推荐指数
1
解决办法
9941
查看次数

什么是PushFrame需要?

我遇到了对象的PushFrame方法Dispatcher.它是方法的简化版本:

public void PushFrame(DispatcherFrame frame)
{
    // Stuff
    _frameDepth++;

    while(frame.Continue)
    {
        // Getting and dispatching messages
    }

    _frameDepth--;
    // Stuff
}
Run Code Online (Sandbox Code Playgroud)

换句话说,它只是打开新的消息处理循环.但我真的无法理解这种方式的好处.出于什么目的PushFrame使用?它的用法有很好的例子吗?至于我,似乎这种方法会导致不明显的错误.

c# wpf dispatcher

2
推荐指数
1
解决办法
1157
查看次数