控制台应用程序中的FileVersionInfo.GetVersionInfo()不正确

我使用FileVersionInfo.GetVersionInfo()得到了一些严重的怪异,并希望有人可以提供帮助。 问题的基础是我正在遍历每个文件夹中调用GetVersionInfo()的所有文件。 大约有300个文件。 这适用于除2个文件之外的所有文件。 对于这些DLL,我从GetVersionInfo()得到了完全不正确的信息。 为了消除所有其他变量,我将此调用提取到一个简单的测试应用程序中,它仍然遇到了同样的问题。 但是,如果我将测试应用程序构建为Windows应用程序(最初是控制台应用程序),那么数据会恢复正常。 只是为了澄清一下,当作为控制台应用程序运行时返回的不正确数据不仅仅是如果文件不包含版本数据就会得到的空信息。 它包含合理的数据,但只包含错误的数据。 就好像是从不同的文件中读取它一样。 我找了一个包含匹配版本数据的文件,但找不到。 如果构建为控制台应用程序而不是Windows应用程序,为什么这个简单的调用function会不同? 如果有人可以帮助我,我将非常感激。 安德,安迪 – 已添加代码 using System; using System.Diagnostics; namespace test { class Program { static void Main(string[] args) { string file = “C:\\ProblemFile.dll”; FileVersionInfo version = FileVersionInfo.GetVersionInfo(file); string fileName = version.FileName; string fileVersion = version.FileVersion; Console.WriteLine(string.Format(“{0} : {1}”, fileName, fileVersion)); } } }

WM_KEYDOWN:如何使用它?

我正试图通过PostMessage向一个应用程序发送一个关键笔划。 我使用太Spy ++试图理解如何发送消息,因为我不完全理解它的内部工作原理。 在这张照片中,第一个项目(选定项目)是由我自己制作的实际击键。 它周围有一个红色椭圆(下图)的代码是用以下代码制作的: WinApi.PostMessage(InsideLobbyHandle, WinApi.WM_KEYDOWN, (int)WinApi.VK_UP, 1); 我想它必须与最后一个PostMessage()参数有关,但我无法弄清楚它是如何工作的。 我可以在原始键击中看到ScanCode = 48,而在我的0中,fExtended是1,而我的是0.我怎么能让它看起来一样? 在http://msdn.microsoft.com/en-us/library/ms646280(VS.85).aspx我无法理解最后一个参数的工作原理。

如何使用C#将jpg文件转换为位图?

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace convert { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load_1(object sender, EventArgs e) { // Image image = Image.FromFile(@”C:\Users\Public\Pictures\Sample Pictures\Koala.jpg”); // Set the PictureBox image property to this image. […]

无法将类型’System.EventHandler’隐式转换为’System.EventHandler ‘以完成情节提要

我已经阅读了一些关于此的线索,但我仍然不知道如何在我的情况下解决它。 我来自Java,而且大多是C#的新手 我想在动画结束时附加监听器: myStoryBoard.Completed += new EventHandler(onMyStoryBoardCompleted); 和: private void onMyStoryBoardCompleted(object sender, EventArgs e) { } 我在标题中得到错误。 我试过了: myStoryBoard.Completed += new EventHandler(onMyStoryBoardCompleted); 但后来我得到: no overload for ‘onMyStoryBoardCompleted’ matches delegate ‘System.EventHandler’ 所以似乎签名与EventHandler 不兼容,我找不到如何使它兼容,我也不知道这种方法是否正确。 我读 了解C#中的事件和事件处理程序 从System.EventHandler到System.EventHandler 的C#动态模板隐式转换错误 在Windows 8应用程序中为DispatcherTimer的Tick事件定义事件处理程序 但仍然没有找到这种情况的解决方案。 提前致谢。

从Saxon 9.4he中的嵌入资源加载xml和xslt

我使用Saxon 9.4家庭版( Saxon-HE 9.4 .NET )来获得对XSLT 2.0和XPath 2.0以及.NET中的XQuery 1.0的支持。 当我加载没有URI的文件时,我的代码崩溃了。 是否可以在没有与加载的文档相关的URI的情况下加载xml / xsl文档? 如果没有,有没有办法为嵌入在dll文件中的元素定义URI? 任何其他解决方案也将受到赞赏,我唯一的术语是必须从dll文件中加载文件。 只要我从文件加载xml / xsl,我的代码就可以正常工作: const string sourcePath = @”C:\test\TestInvoiceWithError.xml”; const string xsltpath = @”C:\test\UBL-T10-BiiRules.xsl”; 当我尝试从嵌入式资源加载时,代码抛出一个exception,说明“没有提供基本URI” : Stream sourceStream = GetEmbeddedResource(“TestProject1.testfiles.TestInvoice.xml”); Stream xsltStream = GetEmbeddedResource(“TestProject1.testfiles.UBL-T10-BiiRules.xsl”); 我还为具有相对路径的资源创建了Uri,这会引发exception“相对URI不支持此操作”。 : Uri sourceUri = new Uri(“/TestProject1;component/testfiles/TestInvoice.xml”, UriKind.Relative); Uri xsltUri = new Uri(“/TestProject1;component/testfiles/UBL-T10-BiiRules.xsl.xml”, UriKind.Relative); 这是我的代码: using System; […]

OfType ()与Where()扩展中的检查类型之间的区别

除了可读性之外,以下linq查询之间的区别是什么,以及何时以及为什么我将使用其中一个: IEnumerable items = listOfItems.Where(d => d is T).Cast(); 和 IEnumerable items = listOfItems.OfType(); 更新: Dang,抱歉在尝试简化我的问题时介绍了一些错误

我应该使用set once变量吗?

这闻到了吗? 我有一些你只能设置一次的属性。 它们可以在对象存在期间的任何时间设置,并且无法撤消。 我就是这样实现的。 private FooThingy _foo; public FooThingy Foo { set { if (null == _foo) _foo = value; } get { return _foo; } } 但我不喜欢它。 我觉得我错过了什么。 我有没有? 编辑 :为什么我在构造函数中没有它。 我不能进入细节,但设置这个结果<坏类比>熔化蜡像< /坏比喻> 。 而且我不希望我的构造函数创建已经融化的对象。

如何使用ExecuteScalar检索多个列?

我使用ExecuteScalar获取一列: cmd.commandtext = “select rodeuser from customer_db_map”; string rodecustomer = cmd.executescalar; 但我需要获得多个专栏,例如: cmd.commandtext = “select rodeuser,username,password from customer_db_map”; 我需要字符串中的每一列: string rodecustomer = cmd.ExecuteScalar(); string username= cmd.ExecuteScalar(); string password = cmd.ExecuteScalar(); 但这是不可能的。 这是如何实现的?

.NET Dictionary实现如何与可变对象一起使用

我知道不建议使用“可变”对象(GetHashCode()方法在将它们用作Dictionary中的键时可以返回不同结果的对象)。 下面是我对作为哈希表实现的字典如何工作的理解: 当我添加新密钥时,例如dict.Add(m1, “initially here was m1 object”); , dict使用GetHashCode()方法计算m1的哈希码。 然后它进行一些内部计算,最后将此对象放入其内部数组的某个位置。 当我使用键索引来获取值时,例如dict[m1] , dict再次计算哈希码。 然后它做了一些内部计算,它给了我一个对象,它位于其内部数组内部的计算位置。 但我认为有一个我无法找到的错误。 所以我们假设我有这个代码: class MutableObject { Int32 m_value; public MutableObject(Int32 value) { m_value = value; } public void Mutate(Int32 value) { m_value = value; } public override int GetHashCode() { return m_value; } } static void Main(string[] args) { MutableObject m1 […]

c#sharpziplib将文件添加到现有存档

我正在尝试使用以下代码将文件添加到现有存档。 运行时不会显示任何错误或exception,但也不会将任何文件添加到存档中。 有什么想法吗? using (FileStream fileStream = File.Open(archivePath, FileMode.Open, FileAccess.ReadWrite)) using (ZipOutputStream zipToWrite = new ZipOutputStream(fileStream)) { zipToWrite.SetLevel(9); using (FileStream newFileStream = File.OpenRead(sourceFiles[0])) { byte[] byteBuffer = new byte[newFileStream.Length – 1]; newFileStream.Read(byteBuffer, 0, byteBuffer.Length); ZipEntry entry = new ZipEntry(sourceFiles[0]); zipToWrite.PutNextEntry(entry); zipToWrite.Write(byteBuffer, 0, byteBuffer.Length); zipToWrite.CloseEntry(); zipToWrite.Close(); zipToWrite.Finish(); } }