0

I'm trying to run my .NET application, that resides in a network share from our domain, using a RDP Client.

When starting a "full" RDP session (that is, opening the whole desktop) and then running my application from the .exe file, everything works fine.

But when I set this same .exe as the Startup Application Path from the RDP Client , I get the following error:

(PS: I clipped the stack trace to the calls I found myself more important)

System.TypeInitializationException: The type initializer for 'NHibernate.Cfg.Environment' threw an exception. ---> System.ArgumentException: Incorrect Parameter. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
   at System.Security.Policy.PEFileEvidenceFactory.GetLocationEvidence(SafePEFileHandle peFile, SecurityZone& zone, StringHandleOnStack retUrl)
   (...)
   at System.AppDomain.get_Evidence()
   (...)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at NHibernate.Cfg.Environment.LoadGlobalPropertiesFromAppConfig() in p:\nhibernate-core\src\NHibernate\Cfg\Environment.cs:line 212
   at NHibernate.Cfg.Environment..cctor() in p:\nhibernate-core\src\NHibernate\Cfg\Environment.cs:line 198

As I work with shadow-copied files, I set a new AppDomain when the application has just begun (the .exe entry point):

<STAThread()>
Public Sub Main()
    Try
        Dim currentDirectory As DirectoryInfo = New DirectoryInfo(Directory.GetCurrentDirectory)
        Dim runtimeDirectory As DirectoryInfo = New FileInfo(Assembly.GetExecutingAssembly.Location).Directory

        Dim appDomainStartupSetup As New AppDomainSetup
        appDomainStartupSetup.ApplicationBase = currentDirectory.FullName
        appDomainStartupSetup.ShadowCopyFiles = "true"

        Dim appDomainStartup As AppDomain = AppDomain.CreateDomain("StartupAppDomain", Nothing, appDomainStartupSetup)
        Dim entrypointLoader As LoadBaseFiles = appDomainStartup.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly.CodeBase, "MyClass.LoadBaseFiles")
        entrypointLoader.RuntimeDir = runtimeDirectory.FullName ' Setup the 'entry-point' object 
        entrypointLoader.StartupEntryPoint() ' Starts the Application

    Catch ex As Exception
        ' Error Handling Here
    End Try
End Sub

Public Class LoadBaseFiles
    Inherits MarshalByRefObject

    ' Startup stuff here...

End Class

More Info

EDIT:

  • If I copy all the assemblies to a local drive (C:) and run my application from there, it will work fine.

Any advices?

J.Hudler
  • 1,238
  • 9
  • 26

1 Answers1

1

It looks like you're missing an argument or pointing to an unavailable resource.

a) Is the Working Directory set for the application?

b) Is the Working Directory available to the user on login?

EKW
  • 124
  • 2
  • 9
  • There's no nhibernate section in my app.config - all my NHibernate stuff is done programmatically. The App.Config content I posted in the link above is 'as it really is'. The question is why the `System.Configuration.ConfigurationManager.GetSection(String sectionName)` call (and sub-call's) end throwing this `Exception`. – J.Hudler May 09 '13 at 21:17
  • Sorry, I actually completely failed at reading RDP there. Updated my answer. – EKW May 09 '13 at 21:45