Common Language Runtime detected an invalid progra

2020-02-06 05:52发布

问题:

I have been using Visual Studio 2008 quite long but lately I am getting this message when I am developing an application in 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...

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

I would appreciate any help with this issue... :( I do not want to reinstall VS, that will be my last resource...

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.

回答1:

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!



回答2:

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:

<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.



回答3:

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.

Seems VS had gotten a little 'dirty', somehow.



回答4:

Only you have to delete temparory asp.net files from

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.



回答5:

I've encountered this error. Peverify helped with finding the source - it was a method group invocation synthax. Go figure.



回答6:

Try using "Clean Solution" before going through Microsoft's troubleshooting guide.



回答7:

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.

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.

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.



回答8:

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:

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)

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).

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 OriginalImage object was defined as a Bitmap in the code that was working, however, I defined it as an Image in the one that did not work.

I further went to the code line above, and checked the parameters / arguments that the "clone" function above takes, the one from the Bitmap instance has the parameters correct and with 3 morphs (i.e. 3 different set of parameters you can call the function with), however, with the Image type instance, the Clone takes no parameters !.

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.

Fixing it was to change the system.drawing.Image into system.drawing.Bitmap, code worked afterwards.

I hope this helps

Kind Regards Heider



回答9:

A colleague of mine had a problem where his toolbox ended up corrupt. Try opening the toolbox, right-click, and choose 'Reset Toolbox'. You never know.



回答10:

Restarting my machine solved this for me. It seems that there a lot of references to this problem that talk about a limitation of the size of a method and the number of local variables. This is only the case for .net framework 2.0 or less. So, your best bet is to Clean, Rebuild, Restart or in the end Re install the Visual Studio. In my experience it is more ofer a 'stuck/corrupt' Visual Studio.



回答11:

This is sort of an old question but I just ran into this problem too.

For me it was simply that I was trying to use untyped objects instead of strongly type variables. I turned option strict on in my ASP.net project properties and fixed all the casting errors that popped up and it works perfectly now.

Something you may want to try before reinstalling VS or one of the other much more time consuming measures others have mentioned.



回答12:

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!



回答13:

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:

<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 program message. I took out one of the <Clear/>s and everything turned into magical rainbows and unicorns.



回答14:

I had the same problem after we installed AppDynamics. The solution was to uninstall AppDynamcis.

We are using .NET remoting, to call are web services. (Legacy project)



回答15:

What I ended up doing was to remove optimizations and integer overflow checking. Removing the trace and debug checkboxes on that same dialog box allowed it to work for me.



回答16:

I am using visual studio 2012 and have large level of project in vb.net. i also face this same problem in my pc during create columns in grid.

I just clean my project and ReBuild it then it is smooth to run.

Thanks you,