Unable to run an asp.net 4.5 app on xsp on Mono 3

2019-04-23 16:11发布

问题:

I've build Mono 3.0.2 from source (tarball), and built XSP from both the latest tarball and the latest on Github, but I'm unable to run a relatively simple asp.net app using .net 4.5 because it sees 'targetFramework="4.5"' in the web.config as invalid. Building the app, and running a console .net 4.5 app works just fine.

This is the web.config in question:

<?xml version="1.0"?>

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

<configuration>
  <appSettings>
    <add key="owin:HandleAllRequests" value="true" />
    <add key="owin:SetCurrentDirectory" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

</configuration>

And this is the exception that xsp4 is throwing:

An exception has occurred while generating HttpException page:
System.NullReferenceException: Object reference not set to an instance of an object
  at System.Web.Util.HttpEncoder.GetCustomEncoderFromConfig () [0x00000] in <filename unknown>:0
  at System.Lazy`1[System.Web.Util.HttpEncoder].InitValue () [0x00000] in <filename unknown>:0

The actual exception which was being reported was:
System.Web.HttpException: Initial exception ---> System.Configuration.ConfigurationErrorsException: Error deserializing configuration section httpRuntime: Unrecognized attribute 'targetFramework'. (/home/srobbins/Projects/nancykatana/NancyKatana/Web.config line
1)
  at System.Configuration.ConfigurationSection.DeserializeSection (System.Xml.XmlReader reader) [0x00000] in <filename unknown>:0
  at System.Configuration.Configuration.GetSectionInstance (System.Configuration.SectionInfo config, Boolean createDefaultInstance) [0x00000] in <filename unknown>:0
  at System.Configuration.ConfigurationSectionCollection.get_Item (System.String name) [0x00000] in <filename unknown>:0
  at System.Configuration.Configuration.GetSection (System.String path) [0x00000] in <filename unknown>:0
  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName, System.String path, System.Web.HttpContext context) [0x00000] in <filename unknown>:0
  at System.Web.Configuration.WebConfigurationManager.GetSection (System.String sectionName) [0x00000] in <filename unknown>:0
  at System.Web.HttpRuntime..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---

And some information about the versions/configuration:

xsp-2.11

  Build Environment
    Install prefix:          /usr/local
    Datadir:                 /usr/local/share
    Libdir:                  /usr/local/lib
    Build documentation:     yes
    Mono 2.0 compiler:       /usr/local/bin/gmcs
    Mono 4.0 compiler:       /usr/local/bin/dmcs
    Target frameworks:       .NET 2.0, .NET 4.0
    Build SQLite samples:    yes
srobbins@ubuntu-vm:~/Downloads/xsp$ /usr/local/bin/mono --version
Mono JIT compiler version 3.0.2 (tarball Tue Jan  8 08:23:06 GMT 2013)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)
srobbins@ubuntu-vm:~/Downloads/xsp$

If I remove the targetFramework elements from the web.config then the error goes away, but I just get a 404, so none of the http modules are getting hooked up.

Any ideas? I've been told that xsp4 should work just fine, but from what I can see it does't appear to have been updated to handle 4.5 at all.

回答1:

Try and edit that file:

 vi /opt/mono/bin/xsp4

(your location might be different, since you compiled it yourself you should know where you stored the files)

In it change the line:

exec /opt/mono/bin/mono $MONO_OPTIONS "/opt/mono/lib/mono/4.0/xsp4.exe" "$@"

With this:

exec /opt/mono/bin/mono $MONO_OPTIONS "/opt/mono/lib/mono/4.5/xsp4.exe" "$@"

And then copy the executable:

cp /opt/mono/lib/mono/4.0/xsp4.exe /opt/mono/lib/mono/4.5/

I hope the Mono guys make it a little bit more fluid in the future so we don't need to manually do this, but for me this manual workaround works!

Again, I've done this under CentOS so it could be a bit different on Ubuntu.



回答2:

I ran into the same issue with MVC 4 and Mono 3. The strangest thing was, that this error suddenly appeared. Reverting my changes didn't help. Eventually I ended up deleting my solution folder and checking out a fresh version. That must have removed some created files. After that, everything worked as before.