小编Nic*_*zee的帖子

无法构建C#项目


我有一些奇怪的问题.
使用此代码时,我无法构建,但它没有给我构建错误.

代码

public void myMethod()
{              
    //This returns a string in JSON format.
    var jsonResponse = myApi.ReadMobileDevice("1");


    dynamic dynamicJson= JsonConvert.DeserializeObject(jsonResponse);

    //THIS LINE BREAKS MY BUILD. NO BUILD ERRORS SHOWN
    var jValue = dynamicJson["general.display_name"];
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我为什么我的构建制动,以及为什么没有显示构建错误?

UPDATE - 输出
*也将var更改为字符串

1>------ Build started: Project: Control, Configuration: Debug x86 ------
1>  Restoring NuGet packages...
1>  To prevent NuGet from downloading packages during build, open the Visual Studio Options dialog, click on the Package Manager node and uncheck 'Allow NuGet to download …
Run Code Online (Sandbox Code Playgroud)

.net c# json dynamic

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

Visual Studio 2017无法加载项目

我正在尝试将我的VS2015项目加载到新安装的VS2017RC中,但它一直给我错误(加载或重新加载时):

你调用的对象是空的.

它还告诉我:

"该项目需要用户输入.重新加载项目以获取更多信息",

但是重新加载会抛出NullRef异常.

我如何知道我的VS实例有什么问题,哪里可以找到有关错误的信息?

我尝试了事件查看器,但这并不是非常有用.

项目形象

解决方案输出

更新
事件查看器信息 事件日志1,应用程序崩溃 事件日志2,Stacktrace

.net c# visual-studio visual-studio-2017

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

使用HMAC-SHA1加密创建OAuth签名返回HTTP 401

问题
您好,我需要对需要OAuth加密的API进行身份验证.
我的方向正确,但我确信我的签名基本字符串有问题.由于HMACSHA1 Hash基于Key和BaseString,因此我得到了错误的oauth_signature.
OAuth签名流程

到目前为止,
我已经能够收集所有必需的数据,其中包括:

  • 消费者密钥
  • 消费者秘密
  • Acces Token
  • Acces Secret
  • Sha1Hased Value(基于Key和Message,其中Message是签名Base string)
  • 签名基本字符串

问题
我因签名无效而返回HTTP(401错误请求).
注意:我很确定这是我如何构建我的签名基本字符串.有关我使用的API文档的信息,请查看底部页面.

代码

GetOAuthToken(执行实际请求)

public static string GetAuthorizationToken()
{
    string TimeInSecondsSince1970 = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
    string Nonce = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(TimeInSecondsSince1970
    + TimeInSecondsSince1970 + TimeInSecondsSince1970));
    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(GetAppleApiUrl.GetUrl(AppleApiUrl.SESSION_TOKEN));
    httpWebRequest.Method = "GET";

    string consumer_secret = Uri.EscapeDataString(Settings.SettingsManager.consumer_secret);
    string token_secret = Uri.EscapeDataString(Settings.SettingsManager.access_secret);

    string signature_base_string = GetSignatureBaseString(TimeInSecondsSince1970, Nonce);
    string SHA1HASH = GetSha1Hash(consumer_secret + "&" + token_secret, signature_base_string);

    string Header = …
Run Code Online (Sandbox Code Playgroud)

.net c# http oauth hmac

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

创建快捷方式会修改目标路径

我正在尝试在我的Windows文件系统上创建一个快捷方式(.lnk).我的代码工作正常.但是,当我在Windows 2008R2服务器上运行相同的控制台应用程序时,它的行为方式不同.

所以我有我的控制台应用程序,接下来会发生什么:
我的程序只是在桌面上创建了一个带有.docx扩展名的快捷方式,并且在我的本地计算机上一切正常.当我在我的服务器上运行相同的控制台应用程序时,它会创建相同的快捷方式,但目标已被修改 ...它将目标更改为.doc文件.

换句话说,当我运行控制台应用程序时:

LOCALMACHINE

创建指向U:\ test.docx的 MyWordFile.lnk

服务器

创建指向U:\ test.doc的 MyWordFile.lnk


这是一种奇怪的行为.这是

代码

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;

namespace TestShortcut
{
    class Program
    {
        static void Main(string[] args)
        {
            //ShortcutTarget
            var sTarget = @"U:\test.docx";

            //ShortCutName
            var sName = @"MyWordFile.lnk";

            IShellLink link = (IShellLink)new ShellLink();
            link.SetPath(sTarget);

            IPersistFile file = (IPersistFile)link;
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            file.Save(Path.Combine(desktopPath, sName), false);
        }
    }

    [ComImport]
    [Guid("00021401-0000-0000-C000-000000000046")]
    internal …
Run Code Online (Sandbox Code Playgroud)

.net c# windows shortcut windows-server-2008

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

使用Google Directory API找不到OrgUnit

程序

我要:

1.从Google Directory API获取一个OrgUnit
2.阅读OrgUnit并收集所需的数据
3.尝试删除我刚刚收集的OrgUnit.

这会以某种方式导致404 [Not Found]错误
请记住我正在使用的DirectoryService类正常工作.
我修改了这个例子中的代码,使其易于阅读,例如:不包括异常处理等.

API

using Google.Apis.Admin.Directory.directory_v1
Run Code Online (Sandbox Code Playgroud)

1.从Google Directory API获取OrgUnit

DirectoryService directoryService = ServiceInitializers.InitializeDirectoryService();
OrgUnit oUnit = directoryService.Orgunits.List(Settings.customerId).Execute().OrganizationUnits.FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)


2.读取OrgUnit并收集所需的数据

string orgUnitPath = oUnit.OrgUnitPath;
Run Code Online (Sandbox Code Playgroud)


3.尝试删除我刚刚收集的OrgUnit

var orgUnitDeleteResult = directoryService.Orgunits.Delete(Settings.customerId, orgUnitPath).Execute();
Run Code Online (Sandbox Code Playgroud)


例外

GoogleApiException未处理Google.Apis.dll中

出现未处理的"Google.GoogleApiException"类型例外情况

其他信息:Google.Apis.Requests.RequestError未找到组织单位[404]

.net c# wcf google-admin-sdk google-directory-api

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

DataGrid中的CSV /文本Wpf

我似乎无法弄清楚如何在DataGrid中添加我的CSV文件.有人可以解释一下我的方法应该是什么吗?

假设我的csv文件中包含以下内容的CSV文件:

ID;Name;Age;Gender
01;Jason;23;Male
02;Lela;29;Female
Run Code Online (Sandbox Code Playgroud)

真的需要一些帮助

c# csv wpf datagrid text

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

通过http发送基本身份验证

我试图从需要基本身份验证的页面中读取源代码.但是,在我的HttpWebRequest中使用Header甚至Credentials,我仍然会收到一个未经授权的异常[401].

string urlAddress = URL;
string UserName = "MyUser";
string Password = "MyPassword";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);    
            if (UserName != string.Empty)
            {
                string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(UserName + ":" + Password));
                request.Headers.Add("Authorization", "Basic " + encoded);
                System.Net.CredentialCache credentialCache = new System.Net.CredentialCache();
                credentialCache.Add(
                    new System.Uri(urlAddress), "Basic", new System.Net.NetworkCredential(UserName, Password)
                );

                request.Credentials = credentialCache;

            }

            HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //<== Throws Exception 401
Run Code Online (Sandbox Code Playgroud)

Fiddler Auth结果

没有Proxy-Authenticate标头.
WWW-Authenticate Header存在:Basic realm ="example"

.net c# http webrequest basic-authentication

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

为什么异常总是被接受为返回类型(抛出时)?

为什么异常总是被接受为返回类型(抛出)?

有效示例1:

  public string foo()
    {
     return "Hello World!";
    }
Run Code Online (Sandbox Code Playgroud)

无效的例子(很明显):

public string foo()
{
 return 8080;
}
Run Code Online (Sandbox Code Playgroud)

有效示例2:

public string foo()
{
 throw new NotImplementedException("Hello Stackoveflow!");
}
Run Code Online (Sandbox Code Playgroud)


我可以看到我的" 无效示例 "是"抛出"而不是"返回"异常,但是,我的方法永远不会返回该方法定义的类型.为什么我的编译器允许这个编译?

.net c# exception-handling compilation exception

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

线程冻结主UI

您好
我正在编写服务器监控应用程序.

    public class Server
    {
            public string SERVERNAME;
            public string ENVIRONMENT;
            public string VERSION;

            public string CPU_PERCETAGE;
            public string CPU_NAME;
            public string CPU_DESCRIPTION;
            public string CPU_VOLTAGE;
    }
Run Code Online (Sandbox Code Playgroud)

我目前有一个Page wihtin我的主窗口,我在那里Exucute并填充数据:
方法

try
 {
   {
    Thread test = new Thread(() =>
    {
     datagrid_Disks.Dispatcher.BeginInvoke(
      new Action(() =>
      {
        datagrid_Disks.ItemsSource = Server.GetDisksInfo(textbox_Username.Text,
                                                           textbox_password.Password,
                                                           textbox_IP.Text,
                                                           textbox_Domain.Text);
      }));
     });
     test.Start();
  }
  catch (UnauthorizedAccessException)
  {
    Worker.ShowModernBox("Onjuiste gebruiksersnaam" + Environment.NewLine + "of wachtwoord.");
  }
  catch (ManagementException)
  {
   Worker.ShowModernBox("Server geeft geen Response." + Environment.NewLine + "Controleer Aub …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf multithreading dispatcher

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

延迟for循环中的更新值

我想用我的网页更新我的价格.
我目前拥有的:

$(document).ready(function() {
        $("#table1").fadeIn(1000, function myLoop()
        {
        var price = 60;

        for ( var i = 0; i <= price; i++ ) {
                $("#price").html("€" + i);              
            }
        });     
    });
Run Code Online (Sandbox Code Playgroud)

我的For循环需要延迟,因此您可以看到价格向上迭代.
任何帮助都表示赞赏!

html jquery for-loop delay

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