Royi Namir
Royi Namir

Reputation: 148524

Use LINQPAD in a website

I'm using LINQPad package from nuget :

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="LINQPad" version="4.51.3" targetFramework="net40" />
</packages>

In a Console app ( FW4.0)

With this simple code :

public static class A
 {
  public static string Dump<T>(this T o)
   {

    var sb = new StringBuilder();
    using (TextWriter writer = LINQPad.Util.CreateXhtmlWriter(true))
    {
        writer.Write(o);
        sb.Append(writer);
    }
    return sb.ToString();

   }
  }

    class Program
    {
        static void Main(string[] args)
        {
            var s = A.Dump(Enumerable.Range(1, 5));
            Console.WriteLine(s);

        }
    }

And as you can see I do see the HTML string :

enter image description here

However - If I create an empty website ( not a web project , I have an existing website) and add the nuget package - same package , same FW4.0 - I get an error :

enter image description here

Worth to mention that the exe is in the Bin :

enter image description here

Question

Why is it happening and what am I missing ?

Upvotes: 1

Views: 425

Answers (1)

Royi Namir
Royi Namir

Reputation: 148524

Well I figure it out how to do it eventually and I hope it will help others.

I had this :

WebSite
  |
  +--- bin
        |
        +---all dlls, EXE

So I've created a new Class library project ----> Nuget---> downloaded the LINQPAD package.

Then In my website's BIN folder , I copied the LINQPAD.EXE file ( it is mandatory , it didn't work otherwise) - and That's it.

I referenced the DLL to the website.

In that DLL I cated this extension method :

   public static class A
   {

    public static string Dump<T>(this T o)
    {

        var sb = new StringBuilder();
        using (TextWriter writer = LINQPad.Util.CreateXhtmlWriter(true))
        {
            writer.Write(o);
            sb.Append(writer);
        }
        return sb.ToString();

    }
}

Now I can invoke string st = dt.Dump() and that HTML is the output of the real DUMP as LINQPAD's.

Demo : in my site , I've created a test page for some services and inspect the response , I DUMP the object , get the HTML and inject it into an IFRAME :

enter image description here

Upvotes: 2

Related Questions