dotnet / dotnet/dotnet-api-docs
ILGenerator.BeginFinallyBlock example is invalid
- Lingua principale
- C#
- Stelle
- 949
- Fork
- 1.7k
- Merge medio
- 2g 19h
- PR unite (30g)
- 52
Descrizione
As discovered by @luboid in https://github.com/dotnet/coreclr/issues/14379#issuecomment-334959413, [the example code for `ILGenerator.BeginFinallyBlock`](https://docs.microsoft.com/en-us/dotnet/api/system.reflection.emit.ilgenerator.beginfinallyblock?view=netcore-2.0#Examples) contains branch out of try block and is thus invalid. When I run it on .Net Framework 4.7 in x64 mode or .Net Core 2.0 (after changing `myAppDomain.DefineDynamicAssembly` to `AssemblyBuilder.DefineDynamicAssembly` and removing the permissions attribute to make it compile on .Net Core 2.0), I get the following exception:
```
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Common Language Runtime detected an invalid program.
at Adder.DoAdd(Int32 , Int32 )
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
at ILGenerator_BeginFinallyBlock.Main() in C:\code\tmp\coreapp\Program.cs:line 109
```
I think the example should be changed, so that it produces valid IL.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Apri la documentazione API collegata di ILGenerator.BeginFinallyBlock e controlla la sezione Examples. Riproduci l'esempio come descritto su .NET Framework 4.7 o .NET Core 2.0, quindi aggiorna l'esempio in modo che non esca più dal blocco try e venga eseguito senza InvalidProgramException.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- csharp
- Ambito
- documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 55/100