Showing posts with label Mono. Show all posts
Showing posts with label Mono. Show all posts

Monday, September 29, 2014

Deploy ASP.NET MVC to Linux

If you received this error when deploying Visual Studio ASP.NET MVC project to Linux/Unix Mono environment:

System.InvalidOperationException
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.aspx
~/Views/Home/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Home/Index.cshtml
~/Views/Home/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml


Chances are the Precompile during publishing option is checked when you published your project, just uncheck it then the error will go away:





Tested ASP.NET MVC 4


Note that if you are deploying ASP.NET MVC project instead of ASP.NET one, the fastcgi_index in configuration file "/etc/nginx/sites-available/default" have to be removed, otherwise you'll receive this error:





Update Oct 4, 2014


Upon further investigation. We can also leave the Precompile during publishing checked, but we must click Configure link, then uncheck the Allow precompiled site to be updatable




Happy Deploying!


Monday, December 27, 2010

Troubleshooting NUnit Testing of Linq on Mono 4.0

At the time of this writing(Mono 2.8.1), you might receive error (TestFixtureSetup failed in MyClass) when you perform NUnit testing of Linq on Mono targeting .NET framework version 4.0. This can be avoided by going back to framework version 3.5. If you don't intend to perform NUnit testing, Linq runs fine on Mono targeting framework version 4.0

The Video: http://www.youtube.com/watch?v=8hhxGVtaosY

Sigh.. Mono should just synchronize their version numbering on .NET framework version

Monday, December 6, 2010

Using NHibernate 3 on Fluent NHibernate 2.0.0.967

If you are like most folks who want to experiment on latest and bleeding edge technology, encountering errors and making your way around it is the way of life. At the time of this writing, you will encounter this error...

cannot implicitly convert type 'NHibernate.ISessionFactory' to 'NHibernate.ISessionFactory'. An explicit conversion exists (are you missing a casts?)


...when you attempt to use Fluent NHibernate 2.0.0.967 on NHibernate 3. The code in question:

static ISessionFactory CreateSessionFactory()
{
 return Fluently.Configure()
  .Database
   (
    PostgreSQLConfiguration.Standard.ConnectionString("Server=localhost;Database=fluent_try;User ID=postgres;Password=xxxx;")
   )
  .Mappings( m => m.FluentMappings.AddFromAssemblyOf<MainClass>() )    
  .BuildSessionFactory();
}


Which seems odd, considering that BuildSessionFactory's method signature is:


public ISessionFactory BuildSessionFactory();
    


Though Fluent NHibernate 2.0.0.967 was built for NHibernate 2.1, the following would do the trick for convincing the compiler that NHibernate 3 is compatible with NHibernate 2.1:

static ISessionFactory CreateSessionFactory()
{
 return (ISessionFactory) Fluently.Configure() // note the explicit cast
  .Database
   (
    PostgreSQLConfiguration.Standard.ConnectionString("Server=localhost;Database=fluent_try;User ID=postgres;Password=xxxxxxxxx;")
   )
  .Mappings( m => m.FluentMappings.AddFromAssemblyOf<MainClass>() )    
  .BuildSessionFactory();
}


Happy Fluenting! :-)

EDIT: 2010-12-10 Apparently, the explicit cast trick works on Mono only, on Visual Studio, it will prompt you to add binding redirect records to app.config

UPDATE: 2010-12-13 There's now an NHibernate 3-compatible Fluent NHibernate: http://fluentnhibernate.org/dls/v1.x/fluentnhibernate-NH3.0-binary-1.2.0.694.zip

Here's the sample code: http://www.ienablemuch.com/2010/12/nhibernate-3-fluent-linq-one-stop-shop.html

Friday, December 3, 2010

Unix transport error when unit testing NHibernate for Postgresql under Mono

If you happen to encounter the following error while doing unit testing for NHibernate for Postgresql under Mono...

Internal error
        RemotingException: Unix transport error.

...Change your Npgsql version to a Mono one, then that error won't happen.

That error will appear on unit testing if you are using MS .NET version of Npgsql (example: http://pgfoundry.org/frs/download.php/2868/Npgsql2.0.11-bin-ms.net4.0.zip) under Mono. When unit testing under Mono, you must use Mono version of Npgsql (example: http://pgfoundry.org/frs/download.php/2860/Npgsql2.0.11-bin-mono2.0.zip)

Weird problem, the error only appear when the code is run under Unit Testing(built-in in MonoDevelop). But when run independently, MS .NET version of Npgsql will run just fine under Mono. Anyway, to make matters simple, use Mono version of the component if you are building Mono stuff





Monday, November 8, 2010

Simulate nested recursive function in C#




This topic was inspired from search keywords that hit my site. I'm wondering why the simulated nested recursive function has a problem in C#. It turns out that compilation problem for recursive lambda in C# is isolated on Microsoft C# compiler only, that wasn't the case for Mono C# compiler (or Mono does an extra mile of performing compiler magic). This works fine on Mono C# (doesn't work on Microsoft C#):

using System;

namespace Craft
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Func<int, int> fib = n => 
            {
                if (n == 0 || n == 1)
                    return 1;
                else
                    return fib(n - 1) + fib(n - 2);
            };
            
            
            for(int i = 0; i < 10; ++i)
                Console.WriteLine ("Hello World! {0}", fib(i));
        }
        
        
    }
}



To make that work in Microsoft C#, "forward declare" the recursive lambda(e.g. Func<int, int> functionNameHere = null) before defining the lambda.

using System;

namespace Craft
{
    class Program
    {
        public static void Main (string[] args)
        {
            // forward declarations evokes C college days :-)
            Func<int, int> fib = null; 

            fib = n => 
            {
                if (n == 0 || n == 1)
                    return 1;
                else
                    return fib(n - 1) + fib(n - 2);
            };
            
            
            for(int i = 0; i < 10; ++i)
                Console.WriteLine ("Hello World! {0}", fib(i));
        }
        
        
    }
}

Sunday, October 31, 2010

Configuring Virtual Directory for ASP.NET on Apache

Just add the necessary entry on /etc/apache2/httpd.conf:

Alias /test "/Users/Michael/Projects/TestAspNetMvc/TestAspNetMvc/"
<Directory "/Users/Michael/Projects/TestAspNetMvc/TestAspNetMvc/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None

    Order allow,deny
    Allow from all
</Directory>
AddMonoApplications default "/test:/Users/Michael/Projects/TestAspNetMvc/TestAspNetMvc/"
<Location /test>
 SetHandler mono
</Location>

Using that example, you can browse your TestAspNetMvc on http://127.0.0.1/test



The How-To Video:



Saturday, October 30, 2010

Troubleshooting for porting an ASP.NET 4 MVC app from .NET to Mono on Mac OS X

If you received this kind of error while porting a fully functioning existing ASP.NET 4 MVC app to Mono on Mac OS X or other *nix ...

Server Error in '/htmlencoder' Application

Compilation Error
Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error.
Compiler Error Message: CS0246: The type or namespace name `Dictionary' could not be found. Are you missing a using directive or an assembly reference?
Source Error:
Line 8: 
Line 9:     Input
Line 10:     <p><%: Html.TextArea("Encode","", new Dictionary<string,object> { { "cols", 120 }, { "rows", 12 } }) %></p>
Line 11: 
Line 12:     

Source File: /Library/WebServer/Documents/HtmlEncoder/Views/Encoder/Index.ascx  Lines: 10, 27

Version information: Mono Runtime Version: 2.8 (tarball Thu Oct 7 12:23:27 MDT 2010); ASP.NET Version: 4.0.30319.1


...then add the necessary namespace to root Web.config of your app(On why it works without including the concerned namespace on .NET is beyond me. Might be some namespace in .NET is automatically included on an ASP.NET MVC app, or Mono is more consistent):

<add namespace="System.Collections.Generic" />

Sample Web.config for adding a namespace in it:

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=152368
  -->

<configuration>
  <system.web>
    <httpRuntime requestValidationMode="2.0" />
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <pages>
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Collections.Generic" /> <!-- add this -->
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Troubleshooting ASP.NET 4 MVC app in Mono on Mac OS X

If you received this kind of error in your ASP.NET MVC application in Mono...

Server Error in '/portal' Application

Compilation Error
Description: Error compiling a resource required to service this request. Review your source file and modify it to fix this error.
Compiler Error Message: : at (wrapper managed-to-native) System.Reflection.MonoMethodInfo:get_method_info (intptr,System.Reflection.MonoMethodInfo&)
~/Global.asax



...then add this at the end of your httpd.conf:

MonoServerPath /Library/Frameworks/Mono.framework/Commands/mod-mono-server4

...and add this after your AddHandler:

MonoAutoApplication disabled

Complete sample entry in httpd.conf:
Include /etc/apache2/mod_mono.conf


AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd
MonoAutoApplication disabled


MonoApplications "/:/Library/WebServer/Documents/"


Alias /portal "/Library/WebServer/Documents/HtmlEncoder/"
AddMonoApplications default "/portal:/Library/WebServer/Documents/HtmlEncoder/"
<Location /portal>
  SetHandler mono
</Location>


MonoServerPath /Library/Frameworks/Mono.framework/Commands/mod-mono-server4