.net 公共语言运行时在 Visual Studio 中检测到无效程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1652630/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Common Language Runtime detected an invalid program in Visual Studio
提问by Jimmy
I have been using Visual Studio 2008 quite long but lately I am getting this message when I am developing an application in C#:
我一直在使用 Visual Studio 2008 很长时间,但最近我在 C# 中开发应用程序时收到此消息:
Common language runtime detected an invalid program
公共语言运行时检测到无效程序
This happens when I try to enter to the properties of a component (text masked box properties, tool box property etc..). But it really became a problem when I tried to launch an other solution that I downloaded from the Developer's 5 star program of Microsoft and it didn't allowed me to launch at all and just got the same problem...
当我尝试输入组件的属性(文本屏蔽框属性、工具框属性等)时会发生这种情况。但是,当我尝试启动从 Microsoft 的 Developer's 5 星程序下载的其他解决方案时,它确实成为一个问题,它根本不允许我启动并且遇到了同样的问题......
I looked for the answer at google but just got some clues about people having the same vague error but in different situations like in ASP.NET
我在谷歌上寻找答案,但只是得到了一些关于人们有同样模糊错误但在不同情况下的线索,比如在 ASP.NET 中
I would appreciate any help with this issue... :( I do not want to reinstall VS, that will be my last resource...
我将不胜感激任何有关此问题的帮助... :( 我不想重新安装 VS,这将是我的最后一个资源...
Update:
更新:
I never figured out what the problem was so I installed a virtual machine with Windows XP on it, there I only have Visual Studio and Netbeans.
我一直不知道问题出在哪里,所以我在上面安装了一个装有 Windows XP 的虚拟机,在那里我只有 Visual Studio 和 Netbeans。
采纳答案by GraemeF
Can you reproduce the problem in a new solution without referencing any extra assemblies? If so, I think reinstalling would be your best bet. Sorry!
您能否在不引用任何额外程序集的情况下在新解决方案中重现该问题?如果是这样,我认为重新安装将是您最好的选择。对不起!
回答by Konstantin Isaev
I faced this issue by trying to invoke System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace() For this case the solution was to edit the project file and make sure the reference to related asembly looks exactly so:
我通过尝试调用 System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace() 遇到了这个问题对于这种情况,解决方案是编辑项目文件并确保对相关程序集的引用看起来完全如此:
<Reference Include="System.Management.Automation" />
Other ways to reference this assembly, via the VS 2012 asseblies picker and by picking the assembly into the physical location of reference assembly.
引用此程序集的其他方法,通过 VS 2012 程序集选择器并将程序集拾取到参考程序集的物理位置。
回答by Daniel
I never did find a solution for this issue online. But what fixed it for me, was to use the 'Clean Solution' option in Visual Studio.
我从来没有在网上找到这个问题的解决方案。但是对我来说修复它的是使用 Visual Studio 中的“清洁解决方案”选项。
Seems VS had gotten a little 'dirty', somehow.
不知何故,VS 似乎有点“脏”了。
回答by Ajmal Shahzad
Only you have to delete temparory asp.net files from
只有您必须从中删除临时的 asp.net 文件
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
and then run your solution in asp.net.Now it will run properly.
然后在 asp.net 中运行您的解决方案。现在它将正常运行。
回答by Gleno
I've encountered this error. Peverify helped with finding the source - it was a method group invocation synthax. Go figure.
我遇到过这个错误。Peverify 帮助找到了源——它是一个方法组调用合成器。去搞清楚。
回答by Heider Sati
Well, (for me), I managed to fix this problem on my side after an hour of investigations.
好吧,(对我来说),经过一个小时的调查,我设法解决了这个问题。
In VB.NET (v4.0 VS-SP1), I found a bug where the compiler does not throw an error neither does the IntelliSense:
在 VB.NET (v4.0 VS-SP1) 中,我发现了一个错误,编译器不会抛出错误,IntelliSense 也不会:
Notice below, if I add the following line in a function (anywhere in the program, Class / Module / Form / etc):
请注意下面,如果我在函数中添加以下行(程序中的任何位置,类/模块/表单等):
MyGraphics.DrawImage(OriginalImage.Clone(New System.Drawing.Rectangle(ClipX1, ClipY1, ClipW, ClipH), Drawing.Imaging.PixelFormat.Format24bppRgb), 0, 0, TempWidth, TempHeight)
MyGraphics.DrawImage(OriginalImage.Clone(New System.Drawing.Rectangle(ClipX1, ClipY1, ClipW, ClipH), Drawing.Imaging.PixelFormat.Format24bppRgb), 0, 0, TempWidth, TempHeight)
The compiler throws this error before it even hits the function while debugging, it does not even reach the line (just adding to the functoin, causes the compiler to be scared of even entering this function).
编译器在调试时甚至在命中函数之前抛出这个错误,它甚至没有到达该行(只是添加到functoin,导致编译器甚至害怕进入这个函数)。
I copied the line from another function in my code, the existing function works fine, however the new one doesn't. Which is quite shocking to be honest.
我从代码中的另一个函数复制了该行,现有函数可以正常工作,但新函数却没有。说实话,这是相当令人震惊的。
Now, I double-checked again and found the cause, as the OriginalImageobject was defined as a Bitmapin the code that was working, however, I defined it as an Imagein the one that did not work.
现在,我再次仔细检查并找到了原因,因为该OriginalImage对象Bitmap在有效的代码中定义为 a ,但是,我将其定义为Image无效的 a。
I further went to the code line above, and checked the parameters / arguments that the "clone" function above takes, the one from the Bitmapinstance has the parameters correct and with 3 morphs (i.e. 3 different set of parameters you can call the function with), however, with the Imagetype instance, the Clonetakes no parameters !.
我进一步转到上面的代码行,并检查了上面“克隆”函数采用的参数/参数,Bitmap实例中的参数/参数正确且具有 3 种变形(即,您可以使用 3 组不同的参数调用该函数) ),但是,对于Image类型实例,Clone不带参数 !。
I was quite shoekd to see this, the problem is that I didn't get any error nor warning in IntelliSense, nor compiler-error, the code compiled fine, but the function couldn't execute, I am sure this is a bug (Ahem... a Feature) in .NET.
看到这个我很震惊,问题是我在 IntelliSense 中没有收到任何错误或警告,也没有编译器错误,代码编译得很好,但函数无法执行,我确定这是一个错误(咳咳…….NET 中的一项功能。
Fixing it was to change the system.drawing.Imageinto system.drawing.Bitmap, code worked afterwards.
修复它是将 in 更改system.drawing.Image为system.drawing.Bitmap,然后代码工作。
I hope this helps
我希望这有帮助
Kind Regards Heider
亲切的问候海德
回答by Alan
Try using "Clean Solution" before going through Microsoft's troubleshooting guide.
在阅读 Microsoft 的故障排除指南之前,请尝试使用“清洁解决方案”。
回答by Ethereal13
Could be the use of a referenced assembly that has a different CPU target of x86 or x64 to the one specified in the solution open in Visual Studio.
可能是使用了引用程序集,该程序集的 CPU 目标与在 Visual Studio 中打开的解决方案中指定的目标不同。
If you can recompile the assembly, set the target of the referenced assembly to the same cpu type as that of the open solution to fix this.
如果可以重新编译程序集,请将引用程序集的目标设置为与开放解决方案相同的 CPU 类型以解决此问题。
My circumstance was running on an x64 cpu with a target of x86 for my solution and a referenced assembly with a CPU target of Any.
我的情况是在 x64 cpu 上运行,我的解决方案目标为 x86,引用程序集的 CPU 目标为 Any。
回答by Harry Gross
I resolved this totally bogus (or at the very least, misleading) error message by correctly using an object in the ADDHANDLER's HandlerObject parameter...I had put a class name in there by mistake!
我通过正确使用 ADDHANDLER 的 HandlerObject 参数中的对象解决了这个完全虚假的(或者至少是误导性的)错误消息......我错误地在那里输入了一个类名!
回答by st3inn
One more possible cause of this: I got this error when implementing Microsoft Fakes in unit testing. One of the .fakes xml files I was starting to manually set up looked like this before I added the namespaces I was going to generate for:
另一个可能的原因是:在单元测试中实现 Microsoft Fakes 时出现此错误。在添加要为其生成的命名空间之前,我开始手动设置的 .fakes xml 文件之一如下所示:
<StubGeneration>
<Clear/>
</StubGeneration>
<ShimGeneration>
<Clear/>
</ShimGeneration>
No tests were running and when I debugged tests in the project with this Fakes setup I got the Common language runtime detected an invalid programmessage. I took out one of the <Clear/>s and everything turned into magical rainbows and unicorns.
没有测试正在运行,当我使用此 Fakes 设置调试项目中的测试时,我发现公共语言运行时检测到无效的程序消息。我拿出其中一个,<Clear/>一切都变成了神奇的彩虹和独角兽。

