除了安装Visual Studio 2012之外,我们现有的应用程序现在在尝试创建委托时崩溃了.
为什么我们在运行我们的应用程序时会遇到这个错误(不是在调试中运行...只是正常运行.exe ...没有重新编译,或者除了安装Visual Studio 2012之外还做了什么)?
Visual Studio 2012是否以某种方式更新.net 4.0 WindowsFormsIntegration?
有关如何绕过这个的任何建议?
'在匹配指定绑定约束的类型'MyWindowsFormsHost'上调用构造函数会引发异常.
内部例外:
无法绑定到目标方法,因为其签名或安全透明性与委托类型的签名或安全透明性不兼容
违规的班级和行:
internal class MyWindowsFormsHost : WindowsFormsHost
{
private delegate void NotifyChildFocus(ref Message m);
private readonly NotifyChildFocus childGotFocus;
public MyWindowsFormsHost()
{
//this line crashes now (and did not before VS2012 install)
this.childGotFocus = Delegate.CreateDelegate(typeof(NotifyChildFocus),
this, "NotifyActivateApp") as NotifyChildFocus;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:发现WindowsFormsHost上不再存在NotifyActiveateApp方法.我不明白的是,使用visual studio 2012安装.net 4.5如何影响我现有的4.0应用程序.
更新:为了解决这个问题,我使用了反射来检查NotifyActivateApp方法是否存在.(如果它不存在,那么应用程序正在修补的.net版本中运行......我不必担心这个子焦点代码被编写修复的激活错误).
MethodInfo methodInfo = (typeof(WindowsFormsHost)).GetMethod("NotifyActivateApp", BindingFlags.NonPublic | BindingFlags.Instance);
if (methodInfo != null)
{
this.childGotFocus = Delegate.CreateDelegate(typeof(NotifyChildFocus), this, "NotifyActivateApp") as NotifyChildFocus;
} …
Run Code Online (Sandbox Code Playgroud) 如果我有:
var myObjects = new ConcurrentBag<object>();
Run Code Online (Sandbox Code Playgroud)
并尝试通过以下方式删除对象:
foreach (var myObject in myObjects.ToArray())
{
myObjects.TryTake(out myObject);
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:"只读局部变量不能用作赋值目标"
然而,如果我在foreach中添加一个本地引用,它将编译:
foreach (var myObject in myObjects.ToArray())
{
var localReference = myObject;
myObjects.TryTake(out localReference);
}
Run Code Online (Sandbox Code Playgroud)
到底发生了什么?
如果许多线程同时调用GetNextNumber
以下代码,GetNextNumber
将比任何其他数字多返回 1 次。
private class RoundRobbinNumber
{
private int _maxNumbers = 10;
private int _lastNumber;
private RoundRobbinNumber(int maxNumbers)
{
_maxNumbers = maxNumbers;
}
public int GetNextNumber()
{
int nextNumber = Interlocked.Increment(ref _lastNumber);
if (_lastNumber > _maxNumbers)
{
Interlocked.CompareExchange(ref _lastNumber, 1, _maxNumbers);
nextNumber = 1;
}
return nextNumber;
}
}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以将返回值重置_lastNumber
为 1,并可靠地为每个调用的线程返回一个递增的数字GetNextNumber()
,而无需使用锁?
我们在 Azure 上部署了一个机器人,但我们想将其提供给客户,以便他可以使用自己的资源部署它并运行它。我们需要给他们一个 Powershell 脚本,它神奇地创建和部署机器人工作所需的所有资源。我的机器人架构由以下部分组成:
我的问题是:
1)如何将bots web api配置为连接字符串参数?(表存储,luis和qna服务重新部署时会有所不同)目前我正在定义conn。web.config 上的字符串和 api 键,但正如我所说,这需要是动态的。
2) 如何自动部署 LUIS?Luis 需要首先创建认知服务帐户的密钥。我假设我有导出的模型 json 文件。我正在考虑使用 LUIS API 来进行应用程序导出和发布部分。这样就够了吗?
3)如何部署qna服务?我认为目前被神奇地部署在某个地方,所以也许我不需要对它做任何事情。
谢谢!
azure-table-storage azure-deployment asp.net-web-api botframework azure-language-understanding
A converter such as what follows will cause the 2008 visual studio designer to not display the xaml, and error out with a "Specified cast is not valid." exception.
public class ItemsVisibilityToGridColumnWidthConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
//THE TWO OFFENDING LINES...
var itemsVisibility = (Visibility)values[0];
var orientation = (Orientation)values[1];
if (orientation == Orientation.Horizontal && itemsVisibility != Visibility.Visible)
{
return new GridLength(0);
}
return new GridLength(4, GridUnitType.Star);
}
public object[] ConvertBack(object value, …
Run Code Online (Sandbox Code Playgroud) 更具体地说,上下文切换的性能下降是否适用于处于等待状态的线程?
在什么条件或情况下,ManualResetEvent或WaitHandle可能会消耗资源?