小编mas*_*son的帖子

编译错误,.NET没有看到存在的函数

我有一个包含以下方法的类库.

namespace TNAUtilities
{
    public class Database
    {
        public static DataView GetDataView(string query)
        {
            //actual implementation omitted, returns a DataView
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我已经使用过这种方法数百次,类库是我在所有项目中都包含的实用程序库.但是,现在我正在开发一个ASP.NET网站,其中一个网页似乎看不到那个方法.我网站上的其他页面都可以看到它.

using TNAUtilities; //top of class

//inside a method body
Database.GetDataView(query); // throws compilation error: 'Database' does not contain a definition for 'GetDataView'
Run Code Online (Sandbox Code Playgroud)

这是我见过的最奇怪的错误.Intellisense能够识别它以实现代码完成,但Visual Studio 2010 Pro以蓝色突出显示方法调用.我实际上在同一页面上调用了这个方法两次,两行都给出了错误.我试过做Build -> Clean Solution但却没有帮助.

我已经将代码部署到服务器几次,服务器报告同样的问题.这可能是罪魁祸首?

.net c# visual-studio-2010

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

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

我在哪里可以在我的c#程序中使用全局变量?

我的导师为我设定了制作C#程序的任务

  • 演示递归(我想我已经做到了)
  • 使用全局变量
  • 可以被企业使用

这就是我想出来的.它只需要是一个小程序,但我不知道在哪里可以使用全局变量.我在考虑减税,但每次开始我都会忘记我的想法.

static void nameCheck()
{
    Console.WriteLine("Name of employee: ");
    string employee = Console.ReadLine();

    string[] employees = { "Emp1", "Emp2", "Emp3", "Emp4" };

    File.WriteAllLines("C:/Users/Chris/Documents/Visual Studio 2013/Projects/ConsoleApplication38/Employees.txt", employees);

    string[] lines = File.ReadAllLines("C:/Users/Chris/Documents/Visual Studio 2013/Projects/ConsoleApplication38/Employees.txt");

    int match = 0;
    foreach (string line in lines)
    {
        if (employee != line)
        {
            match = match + 1;
            if (match > 3)
            {
                Console.WriteLine("That name is not in the employee database, try again:");
                nameCheck();
            }
        }
    }
}
static double payRoll(double hours, …
Run Code Online (Sandbox Code Playgroud)

.net c# global-variables

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

当发送帐户使用两因素身份验证时,如何通过Gmail和SmtpClient发送电子邮件?

            SmtpClient smtpClient = new SmtpClient();
            NetworkCredential basicCredential =
                new NetworkCredential("sender@gmail.com", "password");
            MailMessage message = new MailMessage();
            MailAddress fromAddress = new MailAddress("sender@gmail.com");

            smtpClient.EnableSsl = true;
            smtpClient.Host = "smtp.gmail.com";
            smtpClient.Port = 587;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = basicCredential;

            message.From = fromAddress;
            message.Subject = "your subject";
            //Set IsBodyHtml to true means you can send HTML email.
            message.IsBodyHtml = true;
            message.Body = "<h1>Hello, this is a demo ... ..</h1>";
            message.To.Add("receiver@gmail.com");

            try
            {
                smtpClient.Send(message);
            }
            catch (Exception ex)
            {
                //Error, could not send the message …
Run Code Online (Sandbox Code Playgroud)

c# asp.net smtp

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

发布ASP .NET MVC项目时"无法找到类型或命名空间名称"

我是C#ASP .NET MVC的新手,所以我不太确定很多事情.但是我在我的新公司继承了这个项目,我只是想构建我在这里开始时接管的计算机上存储的文件.我很确定没有人触及这些文件,因为最后一个人离开了,所以我认为代码应该没有问题,因为该网站现在正在运行并正常工作.

但是当我尝试将这些文件发布到临时站点(出于测试目的)时,我得到了一堆相同的错误(取出了错误中给出的完整路径),并且项目无法发布.

    Error   77  The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   15  38  Project
Error   99  The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   17  10  Project
Error   100 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   17 …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc compiler-errors visual-studio-2010

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

我无法访问我的类属性

我有这个C#类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Handler.FTPClient
{
    public class FTP
    {
        private static string _message = "This is a message";

        public static String message
        {
            get { return _message; }
            set { _message = value; }
        }

        public FTP()
        {
        }

        public static String GetMessage()
        {
            return message;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图用这个称呼它:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Handler.FTPClient;

namespace …
Run Code Online (Sandbox Code Playgroud)

c#

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

NewtonSoft Json使用括号方法检索数据

目前,我正在使用YouTube API获取一些数据.数据在json中,我试图获得它的一部分.

我现在面临的问题是我想使用以下方法:

WebClient client = new WebClient();

string jsonData = client.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&part=contentDetails&key=");

var results = JsonConvert.DeserializeObject(jsonData);

string duration = results["items"]["contentDetails"]["duration"];
Run Code Online (Sandbox Code Playgroud)

目前,这会导致错误:

无法将带有[]的索引应用于"object"类型的表达式

我现在面临的问题是我不知道如何正确地反序列化对象,所以我可以使用文本索引来获取数据.我之前曾经这样做过,但我无法回忆起它,也无法找到关于我方法的任何信息.

c# json json.net

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

为什么 HangFire 同名重复性工作不起作用?

我安排了具有相同名称和不同参数的作业,但它没有添加到 hangfire 服务器中,只有最后一个作业添加到服务器中,我错过了什么吗?我的代码在下面

        RecurringJob.AddOrUpdate(
            () => Console.WriteLine("HelloNew jobCreated, "),
            Cron.Minutely);
        RecurringJob.AddOrUpdate(
            () => Console.WriteLine("HelloNew jobCreated 12, "),
            Cron.Minutely);
        RecurringJob.AddOrUpdate(
           () => Console.WriteLine("HelloNew jobCreated 2, "),
           Cron.Minutely);
Run Code Online (Sandbox Code Playgroud)

服务器中只添加最后一个作业 Console.WriteLine("HelloNew jobCreated 2, ");

asp.net asp.net-mvc jobs hangfire

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

C#事件参数有什么作用?

我不明白C#中的事件参数是做什么的.假设我们有一个名为CoffeeButton的按钮,点击它会将您带到另一个名为Coffee的页面,使用名为myFrame的Frame.这是我的代码:

private void CoffeButton_Click(object sender, RoutedEventArgs e)
{
     MyFrame.Navigate(typeof(Coffee));
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下做什么object senderRoutedEventArgs e做什么?

例子很棒!

c# uwp-xaml

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

无法为SSL / TLS C#Web服务客户端建立安全通道

我有一个wpf应用程序,并且在相同的基本url上调用4个Web服务(书面Java),并且在我安装google chrome之前它一直运行良好。我安装了chrome,但出现了这个错误:

无法为SSL / TLS C#Web服务建立安全通道

我没有写另一个代码。那只是我安装了chrome然后删除了chrome但没有用,并且尝试了系统还原,卸载eset smart security并清理了所有Windows(8.1种单一语言)证书的情况。想办法。这是我的网络服务呼叫者

public string call(string url, string json)
{
    try
    {
        var webrequest = (HttpWebRequest)WebRequest.Create(url);
        var key = JsonConvert.SerializeObject(LoginService.SessionData.SessionKey);
        UTF8Encoding uTF8Encoding = new UTF8Encoding();
        byte[] requestBytes = uTF8Encoding.GetBytes(json);
        WebClient client = new WebClient();

        webrequest.Method = "POST";
        webrequest.Headers.Add("SESSION_KEY", LoginService.SessionData.SessionKey);
        webrequest.ContentType = "application/json";
        webrequest.ContentLength = requestBytes.LongLength;
        Stream requestStream = webrequest.GetRequestStream();//here the exception
        requestStream.Write(requestBytes, 0, requestBytes.Length);

        using (var response = webrequest.GetResponse())
        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            var responseBuf = reader.ReadToEnd();
            String responseJson = Convert.ToString(responseBuf); …
Run Code Online (Sandbox Code Playgroud)

c# wpf ssl webservice-client

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