这是我遇到过的最奇怪的问题.我在Windows 2008 R2虚拟机上设置了Go开发环境.我甚至没有重启它也没有运行Windows更新.
今天我才意识到我不能再运行Go程序了.我可以通过'go test'成功构建和运行单元测试.但是,运行任何已编译的Go程序(甚至是hello world)会出现一个标题为"Unsupported 16-bit application"的弹出窗口.错误消息如下:
此文件的版本与您正在运行的Windows版本不兼容.检查计算机的系统信息,以查看是否需要该程序的x86(32位)或x64(64位)版本,然后与软件发行商联系.
无论使用什么版本的Go(x86/x64),结果都是一样的.另请注意,我没有使用任何IDE.我从命令行调用go.exe来构建/测试.
我无法理解这一点,因为运行'go test'工作得很好.
有什么想法吗?
编辑:
这是我构建和运行程序时的控制台输出:
有趣的是,dumpbin表明可执行文件确实存在问题
C:\Program Files (x86)\Microsoft Visual Studio 11.0>dumpbin /headers
C:\Projects \GoPlayground\src\playground\playground.exe Microsoft (R)
COFF/PE Dumper Version 11.00.51106.1 Copyright (C) Microsoft
Corporation. All rights reserved.
Dump of file C:\Projects\GoPlayground\src\playground\playground.exe
File Type: LIBRARY
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4003: invali d library format; library ignored
C:\Projects\GoPlayground\src\playground\playground.exe : warning
LNK4048: Invali d format file; ignored
Summary
C:\Program Files (x86)\Microsoft Visual Studio 11.0>
Run Code Online (Sandbox Code Playgroud)
这是完整的源代码:
package playground
import "fmt"
import "playground/another"
func …
Run Code Online (Sandbox Code Playgroud) 我使用默认的ASP.NET Core MVC模板创建了一个项目.我想在下面创建一个RESTful API /api/{Controller}
.我添加了一个新的Web API控制器(标准Web API控制器类模板),但我无法调用它.我收到一条错误消息,指出无法找到该页面.我尝试在Startup.cs中添加一个路由,但它没有做任何事情:
app.UseMvc(routes =>
{
routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(name: "api", template: "api/{controller=Admin}");
});
Run Code Online (Sandbox Code Playgroud)
编辑:
就像我说的,这都是默认模板.这是我添加的Web API控制器:
[Route("api/[controller]")]
public class AdminController : Controller
{
// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
Run Code Online (Sandbox Code Playgroud) c# asp.net-core-mvc asp.net-core asp.net-core-webapi asp.net-core-routing
我有三个配置文件,每个环境一个:
如果我将ASPNETCORE_ENVIRONMENT设置为dev,我会收到一个运行时异常,抱怨无法找到appsettings.dev.json.我尝试添加
"copyToOutput": [
"appsettings.dev.json"
]
Run Code Online (Sandbox Code Playgroud)
到buildOptions
project.json中的部分,但它似乎没有任何影响.
有没有其他方法可以强制appsettings.dev.json被复制到输出目录?
我刚刚开始在VS2015中使用DNX 1.0.0-rc1-update1.我的第一个应用程序是"控制台应用程序(包)"项目.一切正常,除了NLog日志记录.我怀疑是因为NLog.config没有被复制到输出文件夹.如何通过project.json告诉VS将此文件复制到输出文件夹?
我已经尝试添加这样的'资源'变量,但它不起作用:
project.json
...
"resource":"NLog.config",
...
Run Code Online (Sandbox Code Playgroud)
编辑1: 我正在使用dnx451,因此兼容性不是问题.
编辑2: 我将以下内容添加到project.json中
"scripts": {
"postbuild": [
"%project:Directory%/../scripts/copy_resources.bat \\\"%project:Directory%\\\" \\\"%project:Directory%/../artifacts/bin/%project:Name%/%project:Version%/dnx451\\\""
]
}
Run Code Online (Sandbox Code Playgroud)
copy_resources.bat
echo "Running script" >> C:\logs\log.txt
echo %1 >> C:\logs\log.txt
echo %2 >> C:\logs\log.txt
xcopy %1\NLog.config %2 /U /Y
Run Code Online (Sandbox Code Playgroud)
VS的输出窗口中没有任何内容表明脚本实际上已运行.此外,log.txt为空.
如何调试构建过程?
我将我的项目从1.0.0-rc1-final更新为1.0.0-rc2-final,现在名为ASP.NET Core 2.这是我初始化配置构建器的方法:
var builder = new ConfigurationBuilder().SetBasePath(Environment.GetEnvironmentVariable("ASPNETCORE_CONTENTROOT")).AddJsonFile(file).AddEnvironmentVariables();
IConfiguration configuration = builder.Build();
Run Code Online (Sandbox Code Playgroud)
我确定初始化是可以的,因为我能做到
configuration.AsEnumerable()
Run Code Online (Sandbox Code Playgroud)
在调试器中,查看配置文件中的所有值.
但是,如果我尝试获得这样的整个配置部分
configuration.GetSection(section.Name);
Run Code Online (Sandbox Code Playgroud)
它不起作用.无论我传递给GetSection,它都会返回一个对象.但是,无论该部分是否存在,此对象的Value字段始终为null.
请注意,此之前用于完美运行.有线索吗?
我想实现一个errors.New
接受相同参数的版本,这样fmt.Sprintf
做我写了以下函数:
func NewError(format string, a ...interface{}) error {
return errors.New(fmt.Sprintf(format, a))
}
Run Code Online (Sandbox Code Playgroud)
但是,a
在内部成为单个数组参数,NewError()
从而导致Sprintf()
仅填充格式字符串中的单个参数.我如何强制a
被解释为可变数量的参数?
我面临着一个非常令人费解的问题.我有一个Windows服务,它监视两个MSMQ队列的输入,并将消息发送到另一个MSMQ队列.尽管从服务的角度来看,发送操作似乎是即时的,但它实际上只需要消息三(3)分钟即可到达(如MSMQ MMC中的属性窗口所示).我一直在测试这个问题,没有别的东西在另一边听,所以我可以看到堆积的消息.这是服务发送消息的方式:
var proxyFactory = new ChannelFactory<IOtherServerInterface>(new NetMsmqBinding(NetMsmqSecurityMode.None)
{
Durable = true,
TimeToLive = new TimeSpan(1, 0, 0),
ReceiveTimeout = TimeSpan.MaxValue
});
IOtherServerInterface server = this.proxyFactory.CreateChannel(new EndpointAddress("net.msmq://localhost/private/myqueue"));
var task = new MyTask() { ... };
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
{
server.QueueFile(task);
scope.Complete();
}
Run Code Online (Sandbox Code Playgroud)
该服务在Windows Server 2008 R2上运行.我还在R1上测试了它并注意到了相同的行为.同样,一切都发生在同一台机器上.所有组件都部署在那里,所以我不认为它可能是一个网络问题.
编辑#1:
我打开了WCF诊断程序,我注意到的是非常奇怪的.MSMQ数据报确实正常写入.但是,在"消息被关闭"跟踪消息之后,没有任何事情发生.就好像服务正在等待某事发生.恰好3分钟后,当MSMQ消息到达时(根据MSMQ MMC),我看到另一条关于上一个活动的跟踪消息.我怀疑存在某种干扰.
让我为您提供有关服务如何运作的更多详细信息.有一个IIS应用程序从客户端接收任务并将它们放入MSMQ队列中.从那里,麻烦的服务(MainService)接收它们并开始处理它们.在某些情况下,需要另一个服务(AuxService)来完成任务,因此MainService会向AuxService发送一条消息(总是会延迟).AuxService有自己的收件箱队列,它接收MSMQ消息,一旦完成,它就会向MainService发送一条MSMQ消息.同时,将消息发送到AuxService的线程会一直等到它收到信号或者超时.有一个特殊队列,MainService在其中查找来自AuxServices的消息.当收到消息时,上述线程被唤醒并恢复其活动.
这是整个架构的代表:
尽管所有操作都标有OneWay,但我想知道从另一个MSMQ操作中启动MSMQ操作是否在某种程度上是非法的.鉴于经验证据,似乎就是这种情况.如果是这样,有没有改变这种行为?
编辑#2:
好吧,经过一些挖掘后,似乎WCF是罪魁祸首.我将MainService中的客户端代码和AuxService中的服务器代码都切换为直接使用MSMQ SDK,它按预期工作.我遇到的3分钟超时实际上是MainService放弃并认为AuxService失败的时间.因此,似乎由于某种原因,WCF拒绝执行发送,直到当前WCF活动退出.
这是设计还是错误?这种行为可以控制吗?
我有一个ServiceStack REST服务,我需要实现自定义错误处理.我已经能够通过将AppHostBase.ServiceExceptionHandler设置为自定义函数来自定义服务错误.
但是,对于其他类型的错误,例如验证错误,这不起作用.我怎样才能涵盖所有案件?
换句话说,我正在努力实现两件事:
我将如何实现这一目标?
我有一个包含两个项目的解决方案:一个C#控制台应用程序和一个C库。C库具有一个返回HRESULT的函数。我需要以某种方式更改此函数以使其返回字符串到我的C#代码。它应该是这样的:
C#:
[DllImport("MyLib.dll", SetLastError = true, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern long MyFunction(bunch of params, [MarshalAs(UnmanagedType.BStr)] out string text);
Run Code Online (Sandbox Code Playgroud)
C:
extern "C" HRESULT __declspec(dllexport) MyFunction(bunch of params, BSTR* text)
{
PWSTR finalResult;
//lots of code
(*text) = SysAllocString(finalResult);
//cleanup code
}
Run Code Online (Sandbox Code Playgroud)
我可以更改两个项目。但是,无法知道字符串的大小。因此,我尝试在C库中分配字符串,但这会导致访问冲突异常和各种问题。解决这个问题的最佳方法是什么?
我正在绘制这样的图形:
ig.plot(graph, target=file, vertex_color=membership,
vertex_label=[index for index, value in enumerate(graph.vs)],
vertex_frame_width=0,
palette=ig.ClusterColoringPalette(len(set(membership)) + 3))
Run Code Online (Sandbox Code Playgroud)
该图在单个页面上输出为PDF文件.它看起来不错,但节点太拥挤了.有没有办法拉开节点,以便我可以真正看到所有的边缘?我想增加情节的大小,但我不知道该怎么做.
以下是它现在的样子:
有没有办法从返回值的PowerShell函数将调试消息打印到控制台?
例:
function A
{
$output = 0
# Start of awesome algorithm
WriteDebug # Magic function that prints debug messages to the console
#...
# End of awesome algorithm
return $output
}
# Script body
$result = A
Write-Output "Result=" $result
Run Code Online (Sandbox Code Playgroud)
是否有符合此描述的PowerShell功能?
我知道Write-Output和Write-*,但在我的所有测试中,使用上述函数中的任何函数都不会编写任何调试消息.我也知道只是在不使用返回值的情况下调用函数确实会导致函数编写调试消息.
c# ×7
asp.net ×2
asp.net-core ×2
go ×2
.net ×1
api ×1
c ×1
debugging ×1
delay ×1
dnx ×1
formatting ×1
function ×1
igraph ×1
msmq ×1
pinvoke ×1
plot ×1
powershell ×1
project.json ×1
python ×1
queue ×1
r ×1
rest ×1
servicestack ×1