小编Yur*_*kov的帖子

C#中出错:"非静态字段,方法或属性需要对象引用"

我在WPF中编写代码.首先,我编写了一个单独的项目来测试使用COM端口设备的工作,它运行良好.接下来我决定将它集成到另一个项目中,但是我收到了一个错误.我没有改变代码; 我只是将它复制到一个新的代码文件中.

这段代码效果很好:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO.Ports;
using System.Windows.Threading;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            serial.BaudRate = 9600;
            serial.Handshake = System.IO.Ports.Handshake.None;
            serial.Parity = Parity.None;
            serial.DataBits = 8;
            serial.StopBits = StopBits.One;
            serial.ReadTimeout = 200;
            serial.WriteTimeout = 500;
            serial.DataReceived …
Run Code Online (Sandbox Code Playgroud)

c# wpf delegates dispatcher

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

证书吊销列表 c#

我有一个crl文件。我需要加载它并使用它。它被系统打开得很好。有没有办法在不使用 WinAPi 和 3rd 方库的情况下做到这一点?我试过使用X509Certificate2X509Certificate2Collection Import方法。我收到错误消息:“找不到对象”。CRL 采用 PEM 格式(base64 编码)。

c# cryptography certificate x509certificate

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

从dll调用C函数后,C#代码中的ArithmeticException

我有用C#编写的代码和用C编写的DLL.我试图从DLL调用函数.例如,C中DLL的头文件:

// ---------------------------------------------------------------------------
#ifndef Perspectiva_DLLUnitH
#define Perspectiva_DLLUnitH
// ---------------------------------------------------------------------------
#define DLL_EXPORT __export __stdcall
// ---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C"
{
#endif
UCHAR DLL_EXPORT Init(ULONG TerminalID, CHAR *AzsNo, ULONG *Len);
...
#ifdef __cplusplus
}
#endif
// ---------------------------------------------------------------------------
#endif
Run Code Online (Sandbox Code Playgroud)

这就是我在C#中使用这个DLL的方式:

static class Pers
{
   [DllImport("Perspectiva_DLL.dll", CallingConvention = CallingConvention.StdCall)]
   public static extern byte Init(uint TerminalID, string AzsNo, out uint Len);
   ...
}

...

uint Len = Convert.ToUInt32(AzsNo.Text.Length);
Pers.Init(Convert.ToUInt32(TerminalID.Text), AzsNo.Text, out Len);
Run Code Online (Sandbox Code Playgroud)

函数Init正常工作并返回结果.但是在调用之后,如果我尝试使用界面执行任何操作,例如,更改选项卡,或者只是单击文本框,我会得到一个例外:ArithmeticException.

我无法理解代码中的错误.

例外细节:

System.ArithmeticException was unhandled
  HResult=-2147024362
  Message=???????????? ??? ?????? …
Run Code Online (Sandbox Code Playgroud)

c# wpf dll arithmeticexception

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