ScriptCS Script Pack

200 views
Skip to first unread message

Khalid Abuhakmeh

unread,
Jun 13, 2013, 10:46:19 AM6/13/13
to rav...@googlegroups.com
Hey Guys,

I've started creating a Script Pack for RavenDB to fit into the ScriptCS ecosystem. It works pretty well, except the studio is giving me a weird exception. I wonder if somebody could help me diagnose what the heck the issue is. Oddly the Raven.Client inside of ScriptCS is completely fine calling out to the database and manipulating documents.

Here are the steps to get started.

1. Install ScriptCs through Chocolatey
2. Go to my repository. https://github.com/khalidabuhakmeh/ScriptCs.RavenDB and clone the project
3. Build the solution
4 In a console (after ScriptCs is in the Path), go to the sample folder and run "scriptcs sample.csx"

Reproducing the problem:

So after you have run the steps above, you should realize that RavenDB is now running through the console script. Hit the url it tells you RavenDB is now running under. Most likely http://localhost:8080 or 8081.

You should see the document the script created with an Id of "scriptcs-ravendb"

When you double click on the document to view it, you get a nasty message. The script isn't doing anything crazy as seen below.

Script:

var ravenDb = Require<RavenDB>();
ravenDb.CreateEmbeddableDocumentStore(runInMemory: true);

public class Entry {
    public string Id { get;set; }
    public string Description { get;set; }

    public override string ToString() {
        return Description;
    }
}
var doc = new Entry { 
    Id = "scriptcs-ravendb",
    Description = "scriptcs loves RavenDB"
};

using (var session = ravenDb.OpenSession()) {
    session.Store(doc);
    session.SaveChanges();
}

using (var session = ravenDb.OpenSession()) {
    var loaded = session.Load<Entry>(doc.Id);
    Console.WriteLine(loaded);
}

Console.ReadKey()


Server Error:
-----------------------------------------
/docs/scriptcs-ravendb?noCache=-1681451849
System.ArgumentException: Specified value has invalid Control characters.
Parameter name: value
   at System.Net.WebHeaderCollection.CheckBadChars(String name, Boolean isHeaderValue)
   at System.Net.WebHeaderCollection.SetInternal(String name, String value)
   at Raven.Database.Extensions.HttpExtensions.WriteHeaders(IHttpContext context, RavenJObject headers, Guid etag) in c:\Builds\RavenDB-Stable\Raven.Database\Extensions\HttpExtensions.cs:line 223
   at Raven.Database.Extensions.HttpExtensions.WriteData(IHttpContext context, Byte[] data, RavenJObject headers, Guid etag) in c:\Builds\RavenDB-Stable\Raven.Database\Extensions\HttpExtensions.cs:line 194
   at Raven.Database.Extensions.HttpExtensions.WriteData(IHttpContext context, RavenJObject data, RavenJObject headers, Guid etag) in c:\Builds\RavenDB-Stable\Raven.Database\Extensions\HttpExtensions.cs:line 188
   at Raven.Database.Server.Responders.Document.GetDocumentDirectly(IHttpContext context, String docId) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\Document.cs:line 168
   at Raven.Database.Server.Responders.Document.Respond(IHttpContext context) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\Document.cs:line 43
   at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 864
   at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 609
-----------------------------------------




   at Raven.Studio.Infrastructure.InvocationExtensions.Catch(Task parent, Func`2 func)
   at Raven.Studio.Models.EditableDocumentModel.LoadModelParameters(String parameters)
   at Raven.Studio.Infrastructure.PageViewModel.LoadModel(String state)
   at Raven.Studio.Infrastructure.PageView.OnNavigatedTo(NavigationEventArgs e)
   at System.Windows.Navigation.NavigationService.RaiseNavigated(Object content, Uri uri, Page existingContentPage, Page newContentPage)
   at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content)
   at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
   at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
   at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
   at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
   at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
   at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)



Client side exception:
System.Net.WebException: The remote server returned an error: NotFound.
   at System.Net.Browser.ClientHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Func`2.Invoke(T arg)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise)

Khalid Abuhakmeh

unread,
Jun 14, 2013, 9:02:37 AM6/14/13
to rav...@googlegroups.com
Anybody try this yet and see the same thing I am seeing?

Jeremy Holt

unread,
Jun 15, 2013, 8:44:56 AM6/15/13
to rav...@googlegroups.com
@Khalid

I'm intrigued by ScriptCs. I listened to the interview with Glen Block the other day on Herding Code, but just couldn't get my head around where I would use it? What are you doing with it exactly?

Appreciate your thoughts

Jeremy

Khalid Abuhakmeh

unread,
Jun 15, 2013, 4:26:22 PM6/15/13
to rav...@googlegroups.com
Well I ended up spiking the RavenDB demo for the ScriptCs project. It let's you spin up a embedded RavenDB instance in a console. It is one of the most used ScriptCs demos, and is usually used in their talks. 

The Script Pack is really meant to reduce the overhead even more, to one line to create and start a document store. 

The nice thing about ScriptCS in regards to RavenDB is that you can write really lightweight script files using the RavenDB client you know and love. That way you can play around with loading and querying data without having the overhead of a csproj.

The best way I can analogize ScriptCS is like this:

If C# and Visual Studio are a Tuxedo, then ScriptCS is business casual.

Jeremy Holt

unread,
Jun 16, 2013, 6:37:38 AM6/16/13
to rav...@googlegroups.com
I think I'll go and have a play with it .....

Chris Marisic

unread,
Jun 17, 2013, 1:09:46 PM6/17/13
to rav...@googlegroups.com
Where i want ScriptCS is to stop writing powershell / .bat files and instead write C# automation directly.

Khalid Abuhakmeh

unread,
Jun 18, 2013, 8:35:00 AM6/18/13
to rav...@googlegroups.com
Has someone tried the Scipt Pack yet? I am still having issues with the studio and I don't know why except for the weird "Specified value has invalid Control characters." exception.

Oren Eini (Ayende Rahien)

unread,
Jun 18, 2013, 9:57:48 AM6/18/13
to ravendb
What are those characters? Sorry, don't have time to debug it.


On Tue, Jun 18, 2013 at 3:35 PM, Khalid Abuhakmeh <bird...@gmail.com> wrote:
Has someone tried the Scipt Pack yet? I am still having issues with the studio and I don't know why except for the weird "Specified value has invalid Control characters." exception.

--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Khalid Abuhakmeh

unread,
Jun 18, 2013, 3:22:41 PM6/18/13
to rav...@googlegroups.com
I think there might be a bug in ScriptCS / RavenDB interaction. When RavenDB goes to get the Raven-Clr-Type it ends up picking a name that is freaky. Some kind of fancy R. Checkout the screenshot below. Is there a workaround or something I am missing?

Oren Eini (Ayende Rahien)

unread,
Jun 18, 2013, 5:39:12 PM6/18/13
to ravendb
My guess would be some sort of Unicode interaction.
Can we try doing a team viewer/ skype thingie tomorrow evening?

Khalid Abuhakmeh

unread,
Jun 18, 2013, 8:01:39 PM6/18/13
to rav...@googlegroups.com
What time were you thinking? I am on U.S. eastern and have a hard cut off of 3:00 PM ( 10:00 PM Jerusalem). This is also not super critical, so if tomorrow doesn't work, then we can push it back.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2013, 3:18:43 AM6/19/13
to ravendb
Let us try for around 7 PM my time, if not, we can do it more easily on Friday.

Khalid Abuhakmeh

unread,
Jun 19, 2013, 8:26:20 AM6/19/13
to rav...@googlegroups.com
Let's do it Friday, I have a lot of my plate today, plus I can get my environment set up with the latest RavenDB bits so I don't waste both our time.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2013, 9:34:22 AM6/19/13
to ravendb
okay

Khalid Abuhakmeh

unread,
Jun 19, 2013, 1:41:42 PM6/19/13
to rav...@googlegroups.com
How is the Raven-CLR-Type determined? I am looking through the code base and I can't find it, but surely it is there.

A class name or method name would be helpful. I am narrowing down the issue.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2013, 1:44:00 PM6/19/13
to ravendb

Khalid Abuhakmeh

unread,
Jun 19, 2013, 1:46:51 PM6/19/13
to rav...@googlegroups.com
Conclusive evidence that the crazy R is the issue, but now I'm scratching my head as to why this is happening. This is most likely a ScriptCS / Roslyn issue, but just wondering how it can get into RavenDB but not out.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2013, 1:55:36 PM6/19/13
to ravendb
Put fiddler in there ,what does it says?

Khalid Abuhakmeh

unread,
Jun 19, 2013, 2:08:39 PM6/19/13
to rav...@googlegroups.com
I started a issue with the ScriptCS team. Fiddler doesn't help here, since the server throws a 500 error before the response is built. I assume it gets to the server because the metadata on the way in is part of the body and not part of the headers of the request. This is a really odd and interesting issue.

Oren Eini (Ayende Rahien)

unread,
Jun 19, 2013, 2:27:20 PM6/19/13
to ravendb
A while ago the .NET team used List![[System.Int32]] as the generic names. They broke the windows  build, because ! is important for debugging stuff.
They ended up using ` instead.

You can get away with this by customizing the Clr Type convention

Khalid Abuhakmeh

unread,
Jun 20, 2013, 10:05:32 AM6/20/13
to rav...@googlegroups.com
Ok got the Script Pack done, so you can now use RavenDB (2.0) with ScriptCS. Steps to use it.

- Install Chocalety (http://chocolatey.org/)
- Install ScriptCS through Chocolatey (cinst scriptcs)
- Install Script Pack ( scriptcs -install ScriptCs.RavenDB)
- execute script with ScriptCS ( scriptcs sample.csx) (sample here https://github.com/khalidabuhakmeh/ScriptCs.RavenDB/blob/master/sample/sample.csx)
- Have RavenDB running in a script.

I also solved that nasty serialization bug that Roslyn has by UrlEncoding the type name, since it isn't important.

There you have it! Check it out and see what you think.

Oren Eini (Ayende Rahien)

unread,
Jun 20, 2013, 1:08:21 PM6/20/13
to ravendb
Very cool.
Can you do a kb or a blog post about this?

Khalid Abuhakmeh

unread,
Jun 20, 2013, 2:06:45 PM6/20/13
to rav...@googlegroups.com
Sure, I'll write one up on Tech.Pro, but I'll also post it on the KB. 

As a side note, do you think RavenDB should handle possible unicode characters in the WebHeaderCollection? Take a look at this and tell me what your reaction is.

I only bring this up because I know you are very proud of the Unicode support in RavenDB, but if classes names are unicode then everything explodes.

to recreate just save this class into RavenDB and then try to load the document in the editor and you will see the explosion.

// this is valid C#, but the \u211B will explode WebHeaderCollection which is used in RavenDB
 public class \u211B
    {
        public string Id { get; set; }
        public string Description { get; set; }

        public override string ToString()
        {
            return Description;
        }
    }

Khalid Abuhakmeh

unread,
Jun 20, 2013, 2:50:31 PM6/20/13
to rav...@googlegroups.com
I've posted the tutorial here, if you would like me to update anything or make something more clear please let me know.

Oren Eini (Ayende Rahien)

unread,
Jun 21, 2013, 2:51:14 AM6/21/13
to ravendb
Hi,
Thanks, will be fixed in the next build.

Khalid Abuhakmeh

unread,
Jun 21, 2013, 9:09:25 AM6/21/13
to rav...@googlegroups.com
Cool thank you.
Reply all
Reply to author
Forward
0 new messages