Scott Hanselman

Upgrading FreeTextBox on dasBlog without Recompiling

May 28, 2005 Comment on this post [4] Posted in ASP.NET | DasBlog | XML
Sponsored By

Some folks have had trouble with FreeTextBox under dasBlog not working. The symptom is that the FreeTextBox won't render at all. There's no error and no idea why. It's very frustrating. While we're working on the "no error" issue, the underlying problem isn't dasBlog.

DasBlog builds with a reference to the strongly-typed FreeTextBox 3.0.5000.1. However, you may have 3.0.5000.3. Or, like me, downloaded and installed the latest 3.0.5000.5.

You need to tell .NET that you know what you're doing and say "when you ask for this version, please bind to that version." 

So, added to the web.config of my dasBlog:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>  
            <assemblyIdentity name="FreeTextBox" publicKeyToken="5962a4e684a48b87" culture="neutral"/> 
                <bindingRedirect oldVersion="3.0.0.0-3.0.5000.4" newVersion="3.0.5000.5" /> 
        </dependentAssembly>
    </assemblyBinding>
</runtime>

And everything works great. I suggest you do this if you've updated FreeTextBox. Note also that this is needed regardless of whether FreeTextBox is in the GAC or not.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

NotMuchofAREPL - CSREPL back-ported for .NET 1.1

May 27, 2005 Comment on this post [0] Posted in Programming
Sponsored By

NotsoreplLately Don Box has been exploring just how dynamic a language C# can be.

Here's his REPL for C# code, with backward changes so you can play with it on .NET 1.1 since 1.1 doesn't have anonymous delegates.

I call it NotMuchOfAREPL. Diffs highlighted. I haven't run that many expressions through it so be warned. That said, it's pretty slick. There's a lot of untapped potential in the language (and that wouldn't require IL changes) that could be unlocked with a few new keywords. It's a very exciting time.

    1 using System;
    2 using System.Reflection;
    3 using System.Text;
    4 using System.CodeDom.Compiler;
    5 
    6 namespace notmuchofarepl 
    7 {
    8     class Program 
    9     {
   10         static string funcPrefix = "using System;\r\n"
   11             + "public delegate void Proc();\r\n"
   12             + "public class Wrapper { \r\n"
   13             + "  public static object Set(string name, object value) { \r\n"
   14             + "    AppDomain.CurrentDomain.SetData(name, value);\r\n"
   15             + "    return value; \r\n"
   16             + "  }\r\n"
   17             + "  public static object Get(string name) { \r\n"
   18             + "    return AppDomain.CurrentDomain.GetData(name);\r\n"
   19             + "  }\r\n"
   20             + "  public static object Invoke(Proc proc) { \r\n"
   21             + "    proc();\r\n"
   22             + "    return null; \r\n"
   23             + "  }\r\n"
   24             + "  public static void notSoAnon() { \r\n";
   25         static string funcInter = "  ;"
   26             + "  }\r\n"
   27             + "  public static object Eval() { return ";
   28         static string funcSuffix = "; \r\n} }";
   29 
   30         static string StringEval(string expr, string voidExpr) 
   31         {
   32             string program = funcPrefix + voidExpr + funcInter + expr + funcSuffix;
   33 
   34             ICodeCompiler compiler = new Microsoft.CSharp.CSharpCodeProvider().CreateCompiler();
   35 
   36             CompilerParameters cp = new CompilerParameters();
   37             cp.GenerateExecutable = false;
   38             cp.GenerateInMemory = true;
   39 
   40             CompilerResults results = compiler.CompileAssemblyFromSource(cp, program);
   41             if (results.Errors.HasErrors) 
   42             {
   43                 if (results.Errors[0].ErrorNumber == "CS1525")
   44                     return StringEval("Invoke(new Proc(notSoAnon))",expr);
   45                 return results.Errors[0].ErrorText;
   46             }
   47             else 
   48             {
   49                 Assembly assm = results.CompiledAssembly;
   50                 Type target = assm.GetType("Wrapper");
   51                 MethodInfo method = target.GetMethod("Eval");
   52                 object result = method.Invoke(null, null);
   53                 return result == null ? null : result.ToString();
   54             }
   55         }
   56 
   57         static void Main(string[] args) 
   58         {
   59              while (true ) 
   60             {
   61                 Console.Write("> ");
   62                 Console.Out.Flush();
   63                 string expr = Console.ReadLine();
   64                 if (expr == null)
   65                     break;
   66                 try 
   67                 {
   68                     string result = StringEval(expr, String.Empty);
   69                     Console.WriteLine(result);
   70                 }
   71                 catch (TargetInvocationException ex) 
   72                 {
   73                     Console.WriteLine(ex.InnerException.GetType().Name + ": " + ex.InnerException.Message);
   74                 }
   75                 catch (Exception ex) 
   76                 {
   77                     Console.WriteLine(ex.GetType().Name + ": " + ex.Message);
   78                 }
   79             }
   80          }
   81     }
   82 }

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Ah, crap...

May 25, 2005 Comment on this post [6] Posted in Musings
Sponsored By

Wtfdialogformat

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Machine.Shift.Left and Bit Shifting in VB.NET

May 24, 2005 Comment on this post [7] Posted in Coding4Fun | Tools
Sponsored By

I was converting some C# 2.0 code for the next Coding4Fun Some Assembly Required to VB.NET. I happened to use an automated C# to VB.NET tool to get me started.

It converted this C# code:

if( (btData - '0') <= 9)
{
   receivedChecksum = (byte)((btData - '0') << 4);
}
else
{
   receivedChecksum = (byte)((btData - 'A' + 10) << 4);
}

Into this attempt at VB.NET code.

If btData - "0" <= 9 Then
   
receivedChecksum = System.Convert.ToByte(Machine.Shift.Left((btData - "0"), 4))
Else
  
receivedChecksum = System.Convert.ToByte(Machine.Shift.Left((btData - "A" + 10), 4))
End If

Of course, Machine.Shift.Left (and .Right) doesn't exist. Looks like something that the convertor folks missed? Perhaps they forgot to implement?

At any rate, you can use the standard bit shifting << and >> operators in VB.NET 2.0 like this.

If btData - "0" <= 9 Then
   
receivedChecksum = System.Convert.ToByte((btData - "0") << 4)
Else
   
receivedChecksum = System.Convert.ToByte((btData - "A" + 10) << 4)
End If

And I continue forward...

UPDATED:

You might think that VB.NET would let you use ^= if you can << and >>.

Well, it will compile things like

foo ^= bar

But the ^= operator means Power Of in VB, not Xor as I thought it should. Doh! I'm out of VB.NET practice.

VB.NET folks, I'm sorry, but when it comes down to manipulating raw Bytes, the language sucks.

foo = foo Xor bar

And I continue forward...

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

UML 2.0 Diagrams and Shape Downloads for Microsoft Visio

May 23, 2005 Comment on this post [0] Posted in Ruby
Sponsored By

I was out looking for UML Shapes for Microsoft Visio today. I knew I had found them before, but I couldn't find them for the life of me. Chris Brooks reminded me of Pavel Hruby's most excellent Visio Stencil and Template for UML 2.0 downloads.

He's got versions going all the way back to Visio 4.1, and more importantly he's got one for Visio 2003. He offers them as a free service but appreciates donations via PayPal.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.