我的问题很复杂,但可以归结为一个简单的例子.
我正在编写一种自定义查询语言,用户可以在其中输入我解析为LinQ Expressions的字符串.
我想要做的是按*
字符分割字符串,除非它被正确转义.
Input Output Query Description
"*\\*" --> { "*", "\\", "*" } -- contains a '\'
"*\\\**" --> { "*", "\\\*", "*" } -- contains '\*'
"*\**" --> { "*", "\*", "*" } -- contains '*' (works now)
Run Code Online (Sandbox Code Playgroud)
我不介意Regex.Split
返回空字符串,但我最终得到了这个:
Regex.Split(@"*\\*", @"(?<!\\)(\*)") --> {"", "*", "\\*"}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我尝试过负面的lookbehind,它适用于我的所有情况,除了这个.我也试过了Regex.Escape
,但没有运气.
显然,我的问题是我在找\*
,哪个\\*
匹配.但在这种情况下,
\\
是另一个转义序列.
任何解决方案都不一定要涉及正则表达式.
请注意,此问题与 WCF 连接服务的 .NET Core 实现有关。
我正在将一个普通的 .NET WCF 客户端移植到 .NET Core,但我遇到了这个问题:
The content type text/xml; charset="utf-8" of the response message does
not match the content type of the binding (text/xml; charset=utf-8).
If using a custom encoder, be sure that the IsContentTypeSupported method is
implemented properly. The first 1024 bytes of the response were:
'<?xml version='1.0' encoding='UTF-8'?> [...]
Run Code Online (Sandbox Code Playgroud)
响应确实包含引号:
HTTP/1.1 200 Ok
content-type: text/xml; charset="utf-8"
Run Code Online (Sandbox Code Playgroud)
我从来没有做任何特别的事情来在 WCF 中正确处理这个问题。这是 .NET Core 版本中的错误,还是仅针对内容类型(utf-8 与“utf-8”)进行了具体说明?
如何更改预期的内容类型以匹配我正在调用的服务?(我无法控制它,但如果需要,我可以复制和更改 WSDL)。
我正在使用 svcutil 生成的客户端。(连接服务)
我正在使用Topshelf创建Windows服务。该服务将尝试恢复前3个故障,但此后将不再起作用。
在主机上的“服务”中检查服务将显示:
First Failure: Restart the Service
Second Failure: Restart the Service
Subsequent Failures: Restart the Service
Reset fail count after: 1 days
Restart service after: 2 minutes
Run Code Online (Sandbox Code Playgroud)
服务恢复代码如下所示:
f.EnableServiceRecovery(r =>
{
r.RestartService(2);
r.RestartService(5);
r.RestartService(5);
r.OnCrashOnly();
r.SetResetPeriod(1);
});
Run Code Online (Sandbox Code Playgroud)
恢复失败后,检查事件日志将显示以下消息:
The MyService service terminated unexpectedly. It has done this 1 time(s). The following corrective action will be taken in 120000 milliseconds: Restart the service.
The MyService service terminated unexpectedly. It has done this 2 time(s). The following corrective action will be …
Run Code Online (Sandbox Code Playgroud) 我有一个通用Windows应用程序,主机主菜单.我想要一个插件架构,其中菜单项是从类库中添加的.
但我似乎无法正确加载图像.我无法ms-appx:///
正常工作,当我尝试将图像添加为嵌入式资源时,它会挂起:
var assembly = typeof(CookModule).GetTypeInfo().Assembly;
using (var imageStream = assembly.GetManifestResourceStream("My.Namespace.Folder.ImageName-100.png"))
using (var raStream = imageStream.AsRandomAccessStream())
{
var bitmap = new BitmapImage();
bitmap.SetSource(raStream); //<- Hangs here
Run Code Online (Sandbox Code Playgroud)
我没有例外,输出中的错误或任何东西.它只是挂在那里,应用程序根本不加载页面.
我也尝试过:
var bitmap = new BitmapImage(new Uri("/Folder/ImageName-100.png"));
Run Code Online (Sandbox Code Playgroud)
我遗漏了类似于WPF包uri的东西,我可以说明从哪个程序集加载图像.
从类库中向图像添加图像资源的正确(和工作)方式是什么?(或者有没有人有ms-appx的工作示例,其中图像在类库中)
它是否正确无法绑定到Nullable<T>
Universal XAML应用程序中的任何应用程序?
我从2013年发现了这个链接:
说明:
Windows 8商店应用程序不支持绑定到可空值.它只是没有进入这个版本.我们已经在v.Next上遇到了这种行为的错误.
但它真的可以解决这个问题吗?
我的约束力:
<TextBox Text="{Binding Serves, Mode=TwoWay}" Header="Serves"/>
Run Code Online (Sandbox Code Playgroud)
我的财产:
public int? Serves
{
get { return _serves; ; }
set
{
_serves = value;
OnPropertyChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
我在输出中得到的错误:
Error: Cannot save value from target back to source.
BindingExpression:
Path='Serves'
DataItem='MyAssembly.MyNamespace.RecipeViewModel, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'; target element is 'Windows.UI.Xaml.Controls.TextBox' (Name='null'); target property is 'Text' (type 'String').
Run Code Online (Sandbox Code Playgroud) 我试图在 .NET 6 中为串行通信添加一些安全性,但是当没有任何东西连接到端口(在我的测试台上)时,我无法正确处理端口,因为任何调用SerialPort.Close()
或SerialPort.Dispose()
挂起。
我已设法将其简化为以下 MRE,我在带有 Raspberry Pi 操作系统的 Raspberry Pi 4 上运行该 MRE。我正在将我的应用程序构建为依赖于框架且可移植的应用程序。
using System.IO.Ports;
var sp = new SerialPort("/dev/ttyAMA0", 38400)
{
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
WriteTimeout = TimeSpan.FromSeconds(3).Seconds,
ReadTimeout = TimeSpan.FromMilliseconds(30).Seconds
};
try
{
sp.Open();
sp.WriteLine("123");
}
catch (Exception) { }
finally
{
Console.WriteLine("Closing");
sp.Close(); //Hangs here
Console.WriteLine("Closed");
Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)
我可以采取什么措施来避免应用程序挂起?
我Microsoft.AspNet.Identity.Core 2.2.1
在解决方案中使用。我需要将此与另一个应自动添加声明的系统集成。
为了跟踪哪些索偿是手动添加的,哪些索偿是由外部系统创建的,我想在AspNetUserClaims
表格中添加另一列:
ExternalSystem varchar(64) null
Run Code Online (Sandbox Code Playgroud)
鉴于我的解决方案中实际上没有Claims类,我该如何使用EF迁移(或在没有必要时不使用)进行此操作?
我终于在VS2015上安装了VS2015,以避免为单独安装必要的组件而烦恼,但是现在在构建时遇到了一个新错误。
在我的解决方案上运行MSBuild会产生以下错误:
"C:\Users\Bamboo\bamboo-home\xml-data\build-dir\IMP-COOK-JOB1\Imp.Cook.Api\Imp.Cook.Api.sln" (default target) (1) ->
"C:\Users\Bamboo\bamboo-home\xml-data\build-dir\IMP-COOK-JOB1\Imp.Cook.Api\Imp.Cook.Api\Imp.Cook.Api.csproj" (default target) (2) ->
"C:\Users\Bamboo\bamboo-home\xml-data\build-dir\IMP-COOK-JOB1\Imp.Cook.Api\Imp.Cook.Models\Imp.Cook.Models.csproj" (default target) (3) ->
(ResolveNuGetPackageAssets target) ->
C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets(89,5):
error : The package Microsoft.CSharp with version 4.0.0 could not be found in
C:\Users\Bamboo\.nuget\packages.
Run a NuGet package restore to download the package.
Run Code Online (Sandbox Code Playgroud)
现在,我可以在Bamboo用户目录中手动创建一个.nuget文件夹,这会有所帮助(在下一个包中仍然失败Microsoft.NETCore.Portable.Compatibility
)。
但是我在这里错过了什么难题呢?我nuget restore
在运行msbuild之前先运行,它获取直接在项目中使用的软件包。
Imp.Cook.Models
是针对Windows 10通用应用程序和.NET 4.6的可移植类库。
生成服务器正在运行Windows Server 2012。
c# ×7
uwp ×2
.net ×1
.net-core ×1
asp.net ×1
data-binding ×1
http ×1
msbuild ×1
nuget ×1
raspberry-pi ×1
regex ×1
serial-port ×1
topshelf ×1
wcf ×1
xaml ×1