当Visual Studio未作为管理员启动时,此代码在版本r调试中运行没有问题.
Marshal.GetActiveObject("Outlook.Application");
Run Code Online (Sandbox Code Playgroud)
但是,当我以管理员身份启动Vs并在调试中运行相同的行时,我收到以下错误:
System.Runtime.InteropServices.COMException
Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题.
可以让SpeechSynthesizer以异步方式讲文本,例如:
Private WithEvents _Synth As New SpeechSynthesizer
Private Sub TextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyUp
If e.KeyCode = Keys.Enter Then
_Synth.SpeakAsync(New Prompt(Me.TextBox1.Text))
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
SpeechSynthesizer产生的事件使我们能够分辨出计算机语音在说什么。
例如,您可以通过选择以下字符来可视化语音输出:
Private Sub _Synth_SpeakProgress(sender As Object, e As SpeakProgressEventArgs) Handles _Synth.SpeakProgress
Me.TextBox1.SelectionStart = e.CharacterPosition
Me.TextBox1.SelectionLength = e.CharacterCount
End Sub
Run Code Online (Sandbox Code Playgroud)
但是,当SpeakAsync反复被调用时(例如,当我们告诉SpeechSyntesizer他们当前正在讲话时说相同的文本时),语音请求会排队,然后SpeechSynthesizer一一播放。
但是,我无法找出合成器当前正在发出哪个请求。在SpeakProgressEventArgs不透露这个:
使用SAPI5,事件提供了StreamNumber:
Parameters
StreamNumber
The stream number which generated the event. When a voice enqueues more than one …Run Code Online (Sandbox Code Playgroud) 我有一个在 Windows Docker 容器内运行的 ASP.NET Core WebAPI。我在从应用程序内部连接到本地 SQL 实例时遇到问题。
这是错误消息:
(0x80131904):建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供程序:命名管道提供程序,错误:40 - 无法打开与 SQL Server 的连接)---> System.ComponentModel.Win32Exception (53): 找不到网络路径
我在 github 上发现了这个问题,但它并不真正适用于我的情况。
我可以通过用服务器本地 IP 地址替换实例名称来使一切正常,如下所示:
"ConnectionString_ThrowingError": "Data Source=MySqlInstance; (...)"
"ConnectionString_WorkingFine": "Data Source=192.168.0.123; (...)"
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?.NET 似乎无法解析域机器主机名。
Windows 10和上托管Windows Server 2019。两者都有完全相同的错误。ping使用其主机名或本地 IP 从容器内部获取 SQL 实例。我有多个 web api 项目(微服务),我想只使用一个swagger-ui链接来公开它们。为了这篇文章,我将每个 web api 项目称为EndpointA和EndpointB。
我创建了一个swagger-ui项目,并将每个端点添加到这个项目中。
我的swagger-ui项目Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/EndpointA/swagger/v1/swagger.json", "EndpointA");
c.SwaggerEndpoint("/EndpointB/swagger/v1/swagger.json", "EndpointB");
});
}
Run Code Online (Sandbox Code Playgroud)
我的端点 A/B Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "EndpointA", // or "EndpointB",
});
});
}
Run Code Online (Sandbox Code Playgroud)
我的问题是每个swagger.json文件都不包含端点前缀。而不是/EndpointA/Controller/Action,路径是/Controller/Action,这是无效的。
我试图在我的 swagger ui 项目中设置自定义 url 前缀,如下所示c.RoutePrefix = "EndpointA";。它适用于我的 …
是否可以在本地 SQL Server 实例和 Azure SQL 数据库之间进行事务。
我有以下测试用例。
public class TransactionsTest
{
[Fact]
public void Test1()
{
var premisesDatabaseContext = new OnPremisesDatabaseContext();
var azureSQLDatabaseContext = new AzureSQLDatabaseContext();
using (TransactionScope scope = new TransactionScope())
{
premisesDatabaseContext.Database.Connection.Open();
azureSQLDatabaseContext.Database.Connection.Open();
scope.Complete();
}
}
[Fact]
public void Test2()
{
var premisesDatabaseContext = new OnPremisesDatabaseContext();
var azureSQLDatabaseContext = new AzureSQLDatabaseContext();
using (TransactionScope scope = new TransactionScope())
{
azureSQLDatabaseContext.Database.Connection.Open();
premisesDatabaseContext.Database.Connection.Open();
scope.Complete();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这看起来很简单。但是当我打开第二个连接时,两个测试用例都失败并出现不同的错误。
这是错误的详细信息。
// TEST 1
System.Reflection.TargetInvocationException:
Exception has been thrown by the target …Run Code Online (Sandbox Code Playgroud) 我注意到在某些情况下,Visual Studio建议这样做
await using var disposable = new Disposable();
// Do something
Run Code Online (Sandbox Code Playgroud)
代替这个
using var disposable = new Disposable();
// Do something
Run Code Online (Sandbox Code Playgroud)
using和之间有什么区别await using?
我应该如何决定使用哪个?
当我尝试连接到 Sql Server 时收到此错误消息
===================================
Cannot connect to **SQL_ServerName**.
===================================
Instance failure. (System.Data)
------------------------------
Program Location:
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, Boolean isFirstTransparentAttempt, SqlAuthenticationMethod authType, Boolean disableTnir)
...
Run Code Online (Sandbox Code Playgroud) 如何使用其外部 ID 在数据库中查找记录?
假设我的数据文件中有以下记录:
<record model="product.product" id="product_to_find"> ... </record>
Run Code Online (Sandbox Code Playgroud)
如何在代码隐藏中检索它?
c# ×4
.net ×2
asp.net-core ×2
sql-server ×2
.net-core ×1
c#-8.0 ×1
com-interop ×1
docker ×1
msdtc ×1
odoo ×1
odoo-8 ×1
openerp ×1
python ×1
sql ×1
ssms ×1
swagger ×1
swagger-ui ×1
swashbuckle ×1
vb.net ×1