473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Simple program causes InvalidProgramException

Hello. When I run the program below, I get the exception
System.InvalidProgramException: Common Language Runtime detected an invalid
program. (Visual Studio 2005 version 8.0.50727.51)

I can work around it (by having the delegate point to a helper function).
Basically the purpose of this post is to let someone at Microsoft know about
this bug.

(The generated IL looks OK to me; my guess is that there's a problem in the
verifier.)
namespace Test {
public class Program {
public static void Main() {
Func("hello");
}

private delegate void FuncDelegate<T>(T item);

private static void Func<T>(T item) {
FuncDelegate<Ttemp=new FuncDelegate<T>(Func);
}
}
}

Aug 19 '06 #1
5 2086
Kosak,
Before you start reporting "bugs" , try doing this:

FuncDelegate<stringtemp = new FuncDelegate<string>(Func);

You cannot use "T" as if it were an actual type in the implementation,
its just a placeholder for the actualy type you decide to use.
Hope that helps,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"kosak" wrote:
Hello. When I run the program below, I get the exception
System.InvalidProgramException: Common Language Runtime detected an invalid
program. (Visual Studio 2005 version 8.0.50727.51)

I can work around it (by having the delegate point to a helper function).
Basically the purpose of this post is to let someone at Microsoft know about
this bug.

(The generated IL looks OK to me; my guess is that there's a problem in the
verifier.)
namespace Test {
public class Program {
public static void Main() {
Func("hello");
}

private delegate void FuncDelegate<T>(T item);

private static void Func<T>(T item) {
FuncDelegate<Ttemp=new FuncDelegate<T>(Func);
}
}
}
Aug 20 '06 #2
You are incorrect. If it helps you to appreciate my point, here is a similar
program that creates two delegates, the first one of which triggers the
runtime error and is guarded by a compilation directive.

You can easily control whether the program gets a runtime exception vs runs
successfully, by either commenting out the #define, or not. I hope this
suffices to disprove your claim about T being a placeholder.
#define MAKE_IT_FAIL
using System.Diagnostics;

namespace Test {
public class Program {
public static void Main() {
Func1("hello");
}

private delegate void FuncDelegate<T>(T item);

private static void Func1<T>(T item) {
#if MAKE_IT_FAIL
FuncDelegate<Ttemp1=new FuncDelegate<T>(Func1);
#endif
FuncDelegate<Ttemp2=new FuncDelegate<T>(Func2);
temp2(item);
}

private static void Func2<T>(T item) {
Debug.WriteLine(item);
}
}
}

"Peter Bromberg [C# MVP]" wrote:
Kosak,
Before you start reporting "bugs" , try doing this:

FuncDelegate<stringtemp = new FuncDelegate<string>(Func);

You cannot use "T" as if it were an actual type in the implementation,
its just a placeholder for the actualy type you decide to use.
Hope that helps,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"kosak" wrote:
Hello. When I run the program below, I get the exception
System.InvalidProgramException: Common Language Runtime detected an invalid
program. (Visual Studio 2005 version 8.0.50727.51)

I can work around it (by having the delegate point to a helper function).
Basically the purpose of this post is to let someone at Microsoft know about
this bug.

(The generated IL looks OK to me; my guess is that there's a problem in the
verifier.)
namespace Test {
public class Program {
public static void Main() {
Func("hello");
}

private delegate void FuncDelegate<T>(T item);

private static void Func<T>(T item) {
FuncDelegate<Ttemp=new FuncDelegate<T>(Func);
}
}
}
Aug 20 '06 #3
kosak <ko***@discussions.microsoft.comwrote:
Hello. When I run the program below, I get the exception
System.InvalidProgramException: Common Language Runtime detected an invalid
program. (Visual Studio 2005 version 8.0.50727.51)

I can work around it (by having the delegate point to a helper function).
Basically the purpose of this post is to let someone at Microsoft know about
this bug.

(The generated IL looks OK to me; my guess is that there's a problem in the
verifier.)
Interesting - from the command line, which uses the compiler version
8.00.50727.42 - it all works fine for me.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 20 '06 #4
kosak wrote:
If it helps you to appreciate my point, here is a similar
program that creates two delegates, the first one of which triggers the
runtime error and is guarded by a compilation directive.
This program you produce below causes the error for me (CLR 50727.42),
but not your first program.
#define MAKE_IT_FAIL
using System.Diagnostics;

namespace Test {
public class Program {
public static void Main() {
Func1("hello");
}

private delegate void FuncDelegate<T>(T item);

private static void Func1<T>(T item) {
#if MAKE_IT_FAIL
FuncDelegate<Ttemp1=new FuncDelegate<T>(Func1);
#endif
FuncDelegate<Ttemp2=new FuncDelegate<T>(Func2);
temp2(item);
}

private static void Func2<T>(T item) {
Debug.WriteLine(item);
}
}
}
Peverify fails for the generated assembly, but like you say, the IL
looks good to me. Looks like a JIT compiler bug - Mono executes the
assembly fine, BTW.

To log a bug, you should post it in the Connect site:

http://connect.microsoft.com/visualstudio/

-- Barry

--
http://barrkel.blogspot.com/
Aug 20 '06 #5
Very interesting re the difference between the two programs. I will post
something to Connect as you suggest. Thank you, and also thanks to Jon
Skeet, for your feedback!

Kind regards,
Corey

Aug 20 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Tommy | last post by:
Hi all. I am studying computer security, and I got this short and simple (?) c-code. Something is logical wrong in this code, and if used in the wrong hands of someone, it could be taken advantage...
5
by: Longshot | last post by:
I am new to using C#, and am not able to find any useful help on this error. I am running WinXp, with all the patches and updates. I am working under Visual Studio 2003, and recently I started...
5
by: Sahil Malik [MVP] | last post by:
Okay I installed the LINQ preview on Beta2, and anything I write gives me this error now. The documentation over here - http://msdn.microsoft.com/vs2005/currentreadme/default.aspx aptly tells...
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
13
by: Mike S | last post by:
I came across the following paragraph in the "Semantics" section for simple assignment in N1124 (C99 draft) and I'm wondering if I'm interpreting it right: 6.5.16.1p3: If the value being...
5
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express...
7
by: Pixel.to.life | last post by:
Gurus, Another question on one of the coveted Microsoft products: JIT debugger with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for...
3
by: Pixel.to.life | last post by:
All, A question on JIT debugging with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for managed/unmanaged code). I can also debug it...
0
by: Pixel.to.life | last post by:
Gurus, Another question on one of the coveted Microsoft products: JIT debugger with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.