简体   繁体   English

“不支持URI格式。”异常开始出现在真正陈旧的未更改的代码中

[英]“URI formats are not supported.” exception just started showing up in really old, unchanged code

Ok, I'm experiencing a truly random bug and I cannot find any reason why this would happen. 好吧,我遇到了一个真正的随机错误,我找不到任何理由为什么会这样。 I have an application that I update that was first developed MANY years ago. 我有一个我更新的应用程序,这是多年前首次开发的。 I work on a sizable dev team whose sole responsibility is to manage this application and we've come to accept that the project is a bit of a "franken-code" project. 我在一个规模很大的开发团队工作,他们的唯一责任是管理这个应用程序,我们已经开始接受这个项目是一个“franken-code”项目。 We are but humble developers in a line of many generations of developers who've inherited this project. 在继承这个项目的许多代开发人员中,我们只是谦虚的开发人员。 (This will be important to know later.) (稍后会知道这一点很重要。)

There is a portion of our application that deep within the initialization process calls the following code: 我们的应用程序的一部分在初始化过程的深处调用以下代码:

string strPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
string strFile = strPath.Substring(6) + "\\" + FILE_NAME;

Here's the deal. 这是交易。 My fellow team members, and myself, have been able to modify and build higher-level, UI and DB related sections of our solution for an eternity. 我的团队成员和我自己已经能够永久地修改和构建我们解决方案的更高级别,UI和DB相关部分。 I, nor anyone else, has modified the above code, or any code in the same code file (or project within the solution, for that matter.) 我或其他任何人都修改了上面的代码,或者相同代码文件中的任何代码(或解决方案中的项目)。

However, today while working in a completely different section of my application I began to get some really odd "Out of Memory" exception errors. 然而,今天在我的应用程序的一个完全不同的部分工作时,我开始得到一些非常奇怪的“Out of Memory”异常错误。 I'm not sure if that relates to my problem but I felt it was worth mentioning that after rebooting my machine and reloading the VS solution, I'm now consistently getting the following exception when I attempt to run a debugger test, when the initialization process attempts to execute the above mentioned snippet of code: 我不确定这是否与我的问题有关,但我觉得值得一提的是,在重新启动我的机器并重新加载VS解决方案之后,当我尝试运行调试器测试时,我现在一直得到以下异常进程尝试执行上面提到的代码片段:

Exception: A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll Message: URI formats are not supported. 异常:mscorlib.dll中出现“System.ArgumentException”类型的第一次机会异常消息:不支持URI格式。

I've googled this error message and it looks like the original dev was simply doing this wrong. 我用谷歌搜索了这个错误信息,看起来原来的开发人员只是做错了。 This seems to be a common error , but what baffles me is that this has never been a problem until, randomly, today. 这似乎是一个常见的错误 ,但令我感到困惑的是,这一直是今天随机发生的问题。

I know this is an odd question, but is there a way to fix this without modifying this code. 我知道这是一个奇怪的问题,但有没有办法解决这个问题,而无需修改此代码。 As I mentioned, this is a really complex application that often feels a bit cobbled together. 正如我所提到的,这是一个非常复杂的应用程序,通常会感觉有点拼凑在一起。 Our team is attempting to clean up, or replace, much of the applications functionality but there are portions we simply do not touch because we have no solid clue how the application will work once it is deployed to our production environment. 我们的团队正在尝试清理或替换大部分应用程序功能,但有些部分我们根本不接触,因为我们无法确定应用程序在部署到我们的生产环境后如何工作。 This is a highly-critical application and it cannot be broken. 这是一个非常关键的应用程序,它不能被打破。

Might anyone have any clue what may cause this to "magically" start happening? 任何人都可能有任何线索可能导致这种“神奇地”开始发生吗? Especially since I have been working in UI-related code, and no where near the low-level, configuration resolution section of code where this came from. 特别是因为我一直在使用与UI相关的代码,并且没有接近代码的低级配置解析部分。

ADDITIONAL NOTES 补充笔记

  • We use source control. 我们使用源代码控制。 If I download, build an run an older revision of the application, it works. 如果我下载,构建一个运行较旧的应用程序版本,它的工作原理。
  • We use AnkhSVN and when I inspect my changed files, again, there is nothing that has been changed that relates to the code that is now failing. 我们使用AnkhSVN,当我再次检查更改的文件时,没有任何与现在失败的代码相关的更改。
  • No one else in my team has ever seen this. 我的团队中没有其他人见过这个。
  • To my knowledge, I've not tweaked any setting associated with my project. 据我所知,我没有调整任何与我的项目相关的设置。 I've taken a look at my project properties and everything looks normal. 我看了一下我的项目属性,一切看起来都很正常。 I guess there is a chance that I've hit some odd key-combo and enabled/disabled something through shortcut-keys, but I have no clue what that might be. 我想有可能我通过快捷键击中了一些奇怪的键组合并启用/禁用了某些东西,但我不知道那可能是什么。

Any help is appreciated. 任何帮助表示赞赏。 Sorry for the novel. 对不起小说。 I'm just stumped and I'd rather not use a different method for acquiring this path string if there is ANY chance that altering this process could behave differently in different user environments. 我只是难倒,如果有可能在不同的用户环境中改变这个过程可能会有不同的行为,我宁愿不使用不同的方法来获取此路径字符串。

I can only assume some working file within the Visual Studio that is associated with the project/solution had become corrupt. 我只能假设Visual Studio中与项目/解决方案相关的一些工作文件已损坏。 I searched through the text of my project files, and all of my code, and I didn't see anything out of place. 我搜索了我的项目文件的文本和我的所有代码,但我没有看到任何不合适的地方。

As I mentioned, we use source control. 正如我所提到的,我们使用源代码控制。 To attempt a fix, I pulled down the same source revision that I initially pulled for my current task. 为了尝试修复,我删除了我最初为当前任务提取的相同源代码修订版。 I compiled and ran the application. 我编译并运行了应用程序。 Everything worked properly in its "vanilla" state. 一切都在“香草”状态下正常运作。

Next, I copied in all of the files I knew I had modified. 接下来,我复制了我知道修改过的所有文件。 I hadn't added any new project references or resources, so I just copied over the modified .cs files. 我没有添加任何新的项目引用或资源,所以我只是复制了修改后的.cs文件。 I built and ran the application and I've had no trouble since the pull from my branch. 我构建并运行了应用程序,因为从我的分支中拉出来我没有遇到任何麻烦。

This does not answer the question of why this occurred, but this method can provide a solution to the problem. 这并没有回答为什么会发生这种情况的问题,但这种方法可以解决问题。

I can confirm this change in Path.GetDirectoryName occured to me after installing VS 2015 and rebuilding our project in it so it seams to be .NET 4.6 feature. 我可以在安装VS 2015并在其中重建我们的项目后确认Path.GetDirectoryName中发生的这种变化,因此它接缝为.NET 4.6功能。 Rebuilding the project again in VS 2013 returns the previous behaviour where Assembly.CodeBase with "file:" prefix is acceptable by Path.GetDirectoryName without any exception. 在VS 2013中再次重建项目将返回先前的行为,其中带有“file:”前缀的Assembly.CodeBase可由Path.GetDirectoryName接受,没有任何异常。 But rereading the MSDN documentation, there is a statement that "file:" paths are not supported, but this is not mentioned in ArgumentException thrown in VS 2015 code. 但是重新阅读MSDN文档,有一条声明不支持“file:”路径,但在VS 2015代码中抛出的ArgumentException中没有提到这一点。

First of all, find out how many versions ago this started occuring: start with the current version, and work back changeset by changeset until it no longer fails. 首先,找出这个开始发生的版本:从当前版本开始,然后通过changeset返回changeset,直到它不再失败。

It sounds like, for whatever reason, System.Reflection.Assembly.GetExecutingAssembly().CodeBase now returns a string that GetDirectoryName doesn't like. 听起来,无论出于何种原因, System.Reflection.Assembly.GetExecutingAssembly().CodeBase现在返回一个GetDirectoryName不喜欢的字符串。 So, check the project files, the .sln , the repo config, anything that could cause a file to be in a different location. 因此,请检查项目文件, .sln ,repo配置,以及可能导致文件位于其他位置的任何内容。

If you can't find anything there, check the other files from that same commit, even if they appear that they shouldn't be related. 如果您在那里找不到任何内容,请检查同一提交中的其他文件,即使它们看起来不应该相关。

First Chance Exceptions generally happen when you've got multiple threads happening, so check for new threads that weren't in the previous version. 第一次机会异常通常在您发生多个线程时发生,因此请检查不在先前版本中的新线程。 I've also had situations where First Chance exceptions would only get caught under certain situations, and are silently ignored otherwise, so look changes in Debug settings: it's possible that this problem has always existed, you just haven't had the right settings to catch it until now. 我也遇到过First Chance异常只会在某些情况下被捕获的情况,否则会被忽略,所以看看Debug设置中的更改:这个问题可能一直存在,你只是没有正确的设置抓住它直到现在。

Remember that under a source control, other people can change things that are "yours", even if only by accident. 请记住,在源代码控制下,其他人可以更改“你的”内容,即使只是偶然。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM