KirillOsenkov / RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
http://roslynquoter.azurewebsites.net
Apache License 2.0
918 stars 118 forks source link

Pasting a particular code snippet fails with "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." #54

Closed JesseTG closed 3 years ago

JesseTG commented 4 years ago

When I give the Roslyn Quoter web app the following code sample...

[UnityEngine.CreateAssetMenu(fileName = "Contexts", menuName = "Entitas/Contexts", order = 0)]
public partial class Contexts : UnityEngine.ScriptableObject, Entitas.IContexts {

    public ConfigContext config { get; set; }
    public EngineInputContext engineInput { get; set; }
    public GameContext game { get; set; }
    public GlobalContext global { get; set; }
    public StatusContext status { get; set; }
    public TimerContext timer { get; set; }
    public UiContext ui { get; set; }

    public Entitas.IContext[] allContexts { get { return new Entitas.IContext [] { config, engineInput, game, global, status, timer, ui }; } }

    private void OnEnable() {
        config = new ConfigContext();
        engineInput = new EngineInputContext();
        game = new GameContext();
        global = new GlobalContext();
        status = new StatusContext();
        timer = new TimerContext();
        ui = new UiContext();

        var postConstructors = System.Linq.Enumerable.Where(
            GetType().GetMethods(),
            method => System.Attribute.IsDefined(method, typeof(Entitas.CodeGeneration.Attributes.PostConstructorAttribute))
        );

        foreach (var postConstructor in postConstructors) {
            postConstructor.Invoke(this, null);
        }
    }

    private void OnDisable() {
        ResetContexts();
    }

    public void ResetContexts() {
        var contexts = allContexts;
        for (int i = 0; i < contexts.Length; i++) {
            contexts[i]?.Reset();
        }
    }
}

...and with the following configuration...

...and then click the Get Roslyn API calls to generate this code! button, I get this error instead of code output:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

As a workaround, I can break the posted snippet into smaller blocks and submit those instead. (I'm not using the generated code verbatim, I'm using it as a reference for my own code.)

svick commented 4 years ago

I believe this happens due to a query string length limit of 2048 characters (which is encountered because RoslynQuoter encodes your code into the query string of a GET request). So quoting shorter pieces of code is exactly the right workaround.

Another possible workaround is running RoslynQuoter locally (the limit doesn't seem to apply in that case).

KirillOsenkov commented 4 years ago

What do you guys think is the best way to improve this experience?

  1. Display a better error message?
  2. Limit the number of chars one can enter into the text area?
  3. Find another way to pass larger strings to the web service?
JesseTG commented 4 years ago

I'd prefer Option 3, but Options 2 and 1 are fine if you're short on time.

Is it possible to send strings to the service as a POST request?

KirillOsenkov commented 3 years ago

This seems to be fixed now.