在 Windows 10(版本 10.0.19041)上运行的 .NET 4.8 应用程序启用了 TLS 1.3,使用注册表按照如何在 Windows 10 中启用 TLS 1.3
但是运行以下代码:
try
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
using (var client = new WebClient())
{
var img = client.DownloadData("URL of an image - Only TLS 1.3 at client side - removed for privacy purposes");
MemoryStream ms = new MemoryStream(img);
Image i = Image.FromStream(ms);
i.Save(AppDomain.CurrentDomain.BaseDirectory+"/img1.jpeg");
}
}
catch(Exception ex)
{
logger.Log(LogLevel.Error, ex.ToString());
}
Run Code Online (Sandbox Code Playgroud)
产生以下内容 - 异常 StackTrace:
2020-10-05 12:40:52.4779 ERROR System.Net.WebException: The underlying connection was closed: An unexpected …
Run Code Online (Sandbox Code Playgroud) 我正在使用Cake runner for .NET Framework来构建 .NET Framework 4.8 控制台应用程序。我开始build.ps1
使用:
Invoke-WebRequest https://cakebuild.net/download/bootstrapper/windows -OutFile build.ps1
Run Code Online (Sandbox Code Playgroud)
该文件中没有我自己的更改。我的build.cake
样子是这样的:
Invoke-WebRequest https://cakebuild.net/download/bootstrapper/windows -OutFile build.ps1
Run Code Online (Sandbox Code Playgroud)
看看“AfterBuild”任务。基本上,我想在构建完成后读取一个环境变量并对其进行处理。但是,无论我做什么,cake 似乎都无法捡起它,而是始终使用我提供的默认值。
根据此处的文档,我假设是这样的:
$cake_env="actual env var value"
.\build.ps1
Run Code Online (Sandbox Code Playgroud)
应该工作,但它永远不会。我总是得到默认值:
========================================
AfterBuild
========================================
Running After Build ...
Got value of cake_env from environment: default value
Run Code Online (Sandbox Code Playgroud)
我不想使用参数,所以请不要推荐ScriptArgs
. 我想要环境变量。
尝试编译 Python Django 项目但收到构建错误:
C:\ Program Files \ Microsoft Visual Studio \ 2022 \ Community \ MSBuild \ Current \ Bin \ amd64 \ Microsoft.Common.CurrentVersion.targets(1217,5):错误MSB3644:.NETFramework的参考程序集,版本= v4.0没有找到。要解决此问题,请安装此框架版本的开发人员包(SDK/目标包)或重新定位您的应用程序。您可以在https://aka.ms/msbuild/developerpacks下载 .NET Framework 开发人员包 完成构建项目“myFinancialTracker.pyproj” - 失败。
我该如何解决?
我们有一个 Asp.Net MVC 项目,最近从 .Net 4.6.1 升级到 .Net 4.8。它对我们解决方案中也已升级的其他项目有一些依赖。MVC 项目本身使用 System.IO.Compression 来压缩一些文件,就像它所依赖的其他项目之一一样。
\n自从升级以来,我们发现 System.IO.Compression 出现了一些奇怪的行为。如果我们构建新的解决方案,它不会自动将 System.IO. Compression.dll 和 System.IO. Compression.FileSystem.dll 复制到输出 bin 文件夹。这会导致尝试执行 zipping\xe2\x80\xa6 的代码行出现运行时异常
\nSystem.IO.FileNotFoundException:“无法加载文件或程序集“System.IO.Compression,版本= 4.2.0.0,文化=中性,PublicKeyToken = b77a5c561934e089”或其依赖项之一。该系统找不到指定的文件。'
\n如果 dll 甚至没有复制到 bin 文件夹,我想这并不奇怪。
\n如果我在 MVC 项目引用中的 System.IO.Compression.dll 和 System.IO.Compression.FileSystem.dll 上将“复制本地”属性设置为 true,则文件将从
\n将“C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.8”复制到bin文件夹中,但应用程序首次启动时浏览器中显示以下错误\xe2\ x80\xa6
\n[BadImageFormatException: Cannot load a reference assembly for execution.]\n\n[BadImageFormatException: Could not load file or assembly 'System.IO.Compression' or one of its dependencies. Reference assemblies should not be loaded …
Run Code Online (Sandbox Code Playgroud) 首先是简单的事情:我有一个 .net 4.7.2 clickonce winform 应用程序,它不会在 .net 4.8(Windows 更新附带)安装后立即启动。如果您卸载 .net 4.8 一切正常。当您单击.appref.ms
开始菜单中的快捷方式时会发生什么,它会启动对新版本的检查,然后它就会消失。所以我检查了事件日志,它揭示了这一点:
System.Configuration.ConfigurationErrorsException
at System.Configuration.BaseConfigurationRecord.EvaluateOne(System.String[], System.Configuration.SectionInput, Boolean, System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object)
at System.Configuration.BaseConfigurationRecord.Evaluate(System.Configuration.FactoryRecord, System.Configuration.SectionRecord, System.Object, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(System.String, Boolean, Boolean, Boolean, Boolean, System.Object ByRef, System.Object ByRef)
at System.Configuration.BaseConfigurationRecord.GetSection(System.String)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
at System.Configuration.ConfigurationManager.GetSection(System.String)
at System.ServiceModel.Activation.AspNetEnvironment.GetConfigurationSection(System.String)
at System.ServiceModel.Configuration.ConfigurationHelpers.GetAssociatedSection(System.Configuration.ContextInformation, System.String)
at System.ServiceModel.Configuration.ConfigurationHelpers.GetAssociatedBindingCollectionElement(System.Configuration.ContextInformation, System.String)
at System.ServiceModel.BasicHttpsBinding.ApplyConfiguration(System.String)
at xx.xx.xx.xx.WinClient.Initialize.Execute() …
Run Code Online (Sandbox Code Playgroud) 已安装 Windows Server 2012 R2、IIS 8.5、.NET 4.8(通过注册表验证,请参见屏幕截图)。
在我的 Windows 10 计算机上,我看到从“打开或关闭 Windows 功能”对话框中选择 ASP.NET 4.8 功能的选项。但是,在 Windows 2012 R2 上的“添加服务器角色”向导中,我只看到列出了 ASP.NET 4.5 选项。请参阅屏幕截图进行比较。
我的问题:Windows Server 2012 R2 仅显示 ASP.NET 4.5 选项是否正常?即使安装了更高版本的.NET Framework(例如4.8)?
当我在 Visual Studio 中创建项目时,我无法选择 .net Framework 作为我的目标框架,我只能在 .net core 3 和 .net 5 之间进行选择,我已经下载并安装了 .net Framework 4.8 Developer Pack,但是没有改变。
try
{
string directory = @"D:/user/user.txt";
FileStream FS = new FileStream(directory, FileMode.Append);
StreamWriter SW = new StreamWriter(FS);
string register;
register = $"{generateID()};{txtfirstName.Text};{txtLastName.Text};{txtUser.Text};{txtEmail.Text};{txtPersonalID.Text}";
SW.WriteLine(register);
SW.Close();
FS.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我在 C# Windows Forms .NET Framework 中运行此代码,并且不断收到相同的消息。我正在上大学,我对编程还很陌生,所以我不知道可能出了什么问题。你有什么想法?任何想法?
我的应用程序的客户端是.NET6,服务器端Web API是.NET 4.8。当尝试访问服务器端时,浏览器控制台中会产生以下错误:
从源“https://localhost:34564”获取“https://localhost:12345/api/controller/method”的访问已被 CORS 策略阻止:不存在“Access-Control-Allow-Origin”标头关于所请求的资源。如果不透明响应满足您的需求,请将请求模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
在我的startup.cs中,我有以下代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
// In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/build";
});
services.AddCors(options =>
{
options.AddPolicy("AllowSpecificOrigin",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseCors("AllowSpecificOrigin");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
}); …
Run Code Online (Sandbox Code Playgroud) 我们目前正在将应用程序从 .Net Framework 4.8 更新到 .NET 6,有一件特别的事情让我感到困惑:
"MyString".StartsWith("\x01");
Run Code Online (Sandbox Code Playgroud)
在 .Net Framework 中,这将返回 false。正如我所期望的,因为字符串的第一个字符不是'\x01'
但在 .Net 6 中(也已经有 .Net 5),这个评估结果为 true?我们找不到任何关于为什么这种行为发生变化的解释,您知道我们可以参考什么资源吗?
我们发现,这可以通过使用新的重载来解决StartsWith(char)
,而不是使用字符串参数的(旧的?)重载。
升级路径不会自动替换这些路径,因此我预计行为也会相同。
我正在尝试更改 Windowsform 中 errorProvider 的图标。我已在“属性”->“资源”文件夹中添加了 .ico 文件。我尝试过直接复制粘贴 .ico 文件,还使用了“添加资源”->“添加现有文件”选项。无论我做什么,如果我添加自己的 .ico 文件并尝试将它们设置为 errorProvider 图标(如下面的代码所示),我会在运行程序时遇到异常(特别是在尝试演示程序中的 errorProvider 功能时) 。我的代码是:
private void textBox1_Leave(object sender, EventArgs e)
{
if(string.IsNullOrEmpty(textBox1.Text))
{
textBox1.Focus();
errorProvider1.Icon = Properties.Resources.cross; //here I have change the default icon
errorProvider1.SetError(this.textBox1, "Input UserId"); //having exception in this line
}
else
{
errorProvider1.Icon = Properties.Resources.right;
}
}
Run Code Online (Sandbox Code Playgroud)
异常详细信息:
System.StackOverflowException
HResult=0x800703E9
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Run Code Online (Sandbox Code Playgroud) c# errorprovider windows-forms-designer visual-studio .net-4.8
我有一个使用 IGrouping 的 C# 代码,但我没有这样做,而且我不知道如何修复正在发生的错误。这是代码:
public static class ListExtensions
{
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize) => source.Select((x, i) => new
{
Index = i,
Value = x
})
.GroupBy(x => x.Index / chunkSize)
.Select<IGrouping<int, \u003C\u003Ef__AnonymousType0<int, T>>, List<T>>(x => x.Select(v => v.Value).ToList<T>()).ToList<List<T>>();
Run Code Online (Sandbox Code Playgroud) 我正在创建一个需要每 x 秒运行一次的后台服务。它必须位于 .net Framework 中,因为客户端不想升级到核心或在计算机上安装除此应用程序之外的任何内容。所以我只能使用 Windows 服务
我的主要问题是我要进入一个 while(true) 循环来检查经过的时间(是的,我知道我可以使用计时器),并且我不确定是否应该添加一个线程。在循环中休眠或只保留 while(true)。我主要关心的是不要让 CPU/内存超载。
var nextIteration = DateTime.Now.Add(TimeSpan.FromSeconds(timer * (-1)));
while (true)
{
if (nextIteration < DateTime.Now)
{
RunService();
nextIteration = DateTime.Now.Add(TimeSpan.FromSeconds(timer));
}
}
Run Code Online (Sandbox Code Playgroud)