0

I'm kinda new here and this is my first question. So please don't rage at me when I'm doin something wrong (:

My problem: I'm trying to compile a C# source code in runtime, using CSharpCodeProvider.

It compiles without any problems unless i change the CompilerVersion to "v2.0" using this:

Dictionary<string, string> provOptions = new Dictionary<string, string>();
provOptions.Add("CompilerVersion", "v2.0");

CSharpCodeProvider provider = new CSharpCodeProvider(provOptions);

It shows errors in the 15th line which is this:

15: System.AppDomain.CurrentDomain.AssemblyResolve += (sender, args2) =>
16: {
17:     byte[] assemblydata = Convert.FromBase64String(data);
18:     return Assembly.Load(assemblydata);
19: };

For example:

Line 15, directly after "sender": ) expected

Line 15, directly after "sender": , invalid expression

And some more. I have no idea where the problem comes from. When I use the Visual Studio it compiles fine with "v2.0"

1 Answer 1

4

I would not say something stupid but lambda expression and linq were introduced in C# 3.0, not in C# 2.0.

Instead of using += (sender, args2) => why you don't just use an anonymous delegate? C# 2.0 supports that.

System.AppDomain.CurrentDomain.AssemblyResolve += delegate (object sender, ResolveEventArgs args)
{
    byte[] assemblydata = Convert.FromBase64String(data);
    return Assembly.Load(assemblydata);
};

Or change the compiler to version 3.0.

If I'm wrong please don't rage at me :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for your help (: It works with the anonymous delegate!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.