小编Col*_*lin的帖子

"解析"选项在Visual Studio 2015中的位置在哪里?

在以前版本的Visual Studio中,我曾经能够右键单击未解析的类名,选择"Resolve",然后可以选择添加using语句或完全限定类型.

但是,自安装Visual Studio 2015以来,我似乎缺少该选项.任何人都知道它去了哪里?

visual-studio visual-studio-2015

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

方法调用中的静态变量空,但在程序中初始化

我在这里有点头疼,我想知道是否有人知道答案.

设置基本上是这样的:

//in Visual Studio plug-in application
SpinUpProgramWithDebuggerAttached();

//in spun up program
void Start()
{
    StaticClass.StaticVariable = "I want to use this.";
    XmlSerializer.Deserialize(typeof(MyThingie), "xml");
}

class MyThingie : IXmlSerializable
{
     ReadXml()
     {
         //why the heck is this null?!?
         var thingIWantToUse = StaticClass.StaticVariable;
     }
}
Run Code Online (Sandbox Code Playgroud)

让我脱头发的问题是,在IXmlSerializable.ReadXml()方法中,StaticClass.StaticVariable为null,即使在设置变量后它被称为RIGHT.

值得注意的是,没有命中断点,并且在问题发生的精确位置忽略Debugger.Launch().

神秘的是,我通过提出异常来确定AppDomain.CurrentDomain.FriendlyName属性对于静态变量填充的位置与null相同!

为什么heck是超出范围的静态变量?!?这是怎么回事?!?我如何分享我的变量?

编辑:

我根据响应中的建议添加了一个静态构造函数,并让它执行Debug.WriteLine.我注意到它被调用了两次,即使所有代码似乎都在同一个AppDomain中运行.这是我在输出窗口中看到的内容,我希望这是一个有用的线索:

静态构造函数调用时间:2015-01-26T13:18:03.2852782-07:00

...加载'C:...\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll'...

......加载'Microsoft.GeneratedCode'......

...加载'C:...\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'....

...加载'C:\ USERS ...\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\12.0EXP\EXTENSIONS ... SharePointAdapter.dll'.符号已加载.

...加载'Microsoft.GeneratedCode'.

静态构造函数调用时间:2015-01-26T13:18:03.5196524-07:00

附加细节:

这是实际的代码,因为有几位评论者认为它可能有所帮助:

//this starts a process called "Emulator.exe"
var testDebugInfo = new VsDebugTargetInfo4
{
    fSendToOutputWindow = 1,
    dlo = …
Run Code Online (Sandbox Code Playgroud)

.net c# static-constructor appdomain visual-studio-sdk

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

如何在Web API中支持空RouteAttribute?

我有这门课:

[RoutePrefix("api/v2/Foo")]
public class SomeController : BaseController
{
    [Route("")]
    [HttpGet]
    public async Task<HttpResponseMessage> Get(SomeEnum? param)
    {
        //...
    }
}
Run Code Online (Sandbox Code Playgroud)

我想通过以下方式调用它: api/v2/Foo?param=Bar 但它不起作用.

如果我因此更改路由属性以在RouteAttribute中包含某些内容:

    [Route("SomeRoute")]
    [HttpGet]
    public async Task<HttpResponseMessage> Get(SomeEnum? param)
    {
        //...
    }
Run Code Online (Sandbox Code Playgroud)

...然后我可以打电话 api/v2/Foo/SomeRoute?param=Bar ,但那不是我想要的.

如何让第一个环境工作?

编辑:Domas Masiulis引导我走向答案:上面的场景是可行的,只是默认的全局路由搞砸了.我通过添加符合我们惯例的单独默认路由来解决问题...

    public static void RegisterRoutes(RouteCollection routes)
    {
        //ADDING THIS FIXED MY ISSUE
        routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/v2/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        //SOURCE OF THE ORIGINAL PROBLEM
        routes.MapRoute(
           "Default", // Route name
           "{controller}/{action}/{id}", // URL with …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc-4 asp.net-web-api asp.net-web-api-routing

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

可以手动向SpeechClient提供GoogleCredential(在.NET API中)吗?

我发现的所有SpeechClient文档都涉及在下载SDK后运行命令行,或者笨拙地设置"GOOGLE_APPLICATION_CREDENTIALS"环境变量以指向本地凭据文件.

我讨厌环境变量方法,而是想要一个从应用程序根目录加载共享的,源代码控制的开发帐户文件的解决方案.像这样的东西:

var credential = GoogleCredential.FromStream(/*load shared file from app root*/);
var client = SpeechClient.Create(/*I wish I could pass credential in here*/);
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点,以便我不必依赖环境变量?

.net c# google-cloud-platform google-speech-api

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

Python 层图像失败:“无法导入模块‘lambda_function’:无法从‘PIL’导入名称‘_imaging’”

我只是想在我的 Python 3.8 Lambda 中使用 PIL。

我正在尝试以下步骤:

  1. 基于此 repo:https : //github.com/hidekuma/lambda-layers-for-python-runtime
cd /mydir 
git clone https://github.com/hidekuma/lambda-layers-for-python-runtime.git 
cd lambda-layers-for-python-runtime 
mkdir dist 
docker-compose up --build
Run Code Online (Sandbox Code Playgroud)
  1. 基于此指南:https : //www.splunk.com/en_us/blog/cloud/sharing-code-dependencies-with-aws-lambda-layers.html
aws lambda publish-layer-version --layer-name ImageStorageDependencies
    --description "A Python 3.8 runtime with PIL and boto3 installed." --license-info "MIT" --zip-file fileb://output.zip --compatible-runtimes python3.7 python3.8 --region us-east-2
Run Code Online (Sandbox Code Playgroud)

然后我在 Lamda 配置中选择我的层,但是当我运行此代码时:

import json
import boto3
import io
from PIL import Image


def lambda_handler(event, context): 
    #etc
Run Code Online (Sandbox Code Playgroud)

...我收到错误:

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': cannot import name …
Run Code Online (Sandbox Code Playgroud)

python aws-lambda aws-lambda-layers

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

在 Comprehension 中将列表内容转换为命名元素

我什至很难描述这里发生了什么,但这段代码有效:

list_of_lists = [
  [1.1, 1.2],
  [2.1, 2.2]
]

for (first, second) in list_of_lists:
    print("%s %s" % (first, second))

# output:
# 1.1 1.2
# 2.1 2.2
Run Code Online (Sandbox Code Playgroud)

list_of_lists 的每个内部列表都将元素转换为变量名称“first”和“second”。

这个命名列表内容的过程叫什么?

另外,如果我想将结果转换为等效于的对象:

[
    {
        "first": 1.1,
        "second": 1.2
    },
    {
        "first": 2.1,
        "second": 2.2
    }
]
Run Code Online (Sandbox Code Playgroud)

我怎么能在列表理解中做到这一点?我正在尝试这样的事情,但我正在努力寻找表达我想要做的事情的语法,特别是关于 ???:

results = [??? for (first, second) in list_of_lists]
Run Code Online (Sandbox Code Playgroud)

我知道我可以做一些更详细的事情:

results = [{"first": l[0], "second": l[1]} for l in list_of_lists]
Run Code Online (Sandbox Code Playgroud)

...但我想以更简洁的形式来做,只使用名称而不是列表项索引。

python list-comprehension python-3.x

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