C# 2.0.50727 compiler crashes

T

tsahiasher

the following code crashes my csc.exe (visual studio 2005):

project Base
references: System
BaseClass.cs:
namespace Base
{
public class BaseClass<T>
{
public void BaseFunc()
{
Console.WriteLine("BaseFunc");
}
}
}

project Type
references: System
TClass.cs:
namespace Type
{
public class TClass
{
public void TFunc()
{
Console.WriteLine("TFunc");
}
}
}

project Derived
references: System, Base, Type
DerivedClass.cs:
using Base;
using Type;

namespace Derived
{
public class DerivedClass : BaseClass<TClass>
{
public void DerivedFunc()
{
Console.WriteLine("DerivedFunc");
}
}
}

namespace Main
references: System, Base, Derived
Program.cs:
using Derived;

namespace ConsoleApplication1
{
class Program
{
DerivedClass _obj;

static void Main(string[] args)
{
Program x = new Program();
x.MainFunc();
}

public void MainFunc()
{
_obj = new DerivedClass();
_obj.DerivedFunc();
_obj.BaseFunc(); //crash point
}
}
}

the problem is at calling _obj.BaseFunc(); in Program.MainFunc(). if
you comment this out, the compilation succeeds. another option is to
add a reference to Type in project Main. the thing is, i don't want to
add a reference in Main to a project i'm not using directly, or even
have access to any methods defined in it. i'd like to have as much
seperation between projects as possible.
besides, if this is a syntax error, i should get an error message, not
a compiler crash.

any solutions?
 
M

Marc Gravell

But Derived depends intrinsically on TClass from Type, so I don't see
any way you can avoid this.

I can confirm it dies horribly in 2005, but among the fatal compiler
errors (after the error report) is what you were looking for:

Error 1 The type 'Type.TClass' is defined in an assembly that is not
referenced. You must add a reference to assembly 'Type,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. D:\Develop\Test
\Final\Program.cs 20 13 Final

You can't get around this. The solution is to add the necessary
reference.

However, I have tested it in VS2008, and it works fine - i.e. the
above is the *only* error message (no compiler panic). So it looks
like this has been fixed in the new compiler.
 
T

tsahiasher

But Derived depends intrinsically on TClass from Type, so I don't see
any way you can avoid this.

I can confirm it dies horribly in 2005, but among the fatal compiler
errors (after the error report) is what you were looking for:

Error 1 The type 'Type.TClass' is defined in an assembly that is not
referenced. You must add a reference to assembly 'Type,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. D:\Develop\Test
\Final\Program.cs 20 13 Final

You can't get around this. The solution is to add the necessary
reference.

However, I have tested it in VS2008, and it works fine - i.e. the
above is the *only* error message (no compiler panic). So it looks
like this has been fixed in the new compiler.

then how come there is no problem if i comment out the call to
_obj.BaseFunc() in Program.MainFunc()? if this was a reference
problem, then it wouldn't have mattered if i call this method or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top