bonny
bonny

Reputation: 738

How to stop AppDomain.CurrentDomain.BaseDirectory change during execution.?

I've code in VB.NET windows forms.
I am using AppDomain.CurrentDomain.BaseDirectory for path location but it changes to changes to C:\Windows\System32\spool\Drivers\x64\3\ from other drives (D:\NB) automatically during exe execution.
Issue is I cannot find from where this changes?

NOTE :
I am using crystal reports SP35 version which is latest for now.
I've read somewhere that log4net changes this. if so I have a doubt on it, how do I stop it from changing?

Thanks.

UPDATE
Here is my little code for explanation.

Public Function ConReadData(FName As String, Ar As Integer, ObjectName As String)
    ConReadData = ""
    Try
        msgbox(FName)
        Dim json As String = File.ReadAllText(FName)
        Dim dist As Newtonsoft.Json.Linq.JArray = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Object)(json)
        ConReadData = dist.Item(Ar)(ObjectName)
    Catch ex As Exception
        Throw
    End Try
    Return ConReadData
End Function

Now the issue is the msgbox shows my current directory but after that it shows error regarding this this path. C:\Windows\System32\spool\Drivers\x64\3\

I am sure I haven't used this path anywhere in my project but still this is stuck. Main issue it that it don't show up everytime. I don't know what triggers this to generate the error.

I am also sending photo of the error,

Error

As you can see in the image, it's due to unhandled exception but in the function, I have handled it. Connection.json is my file.
This is not only with this file, after that if I try to export any file, the issue persists.

ADDED ERRORS This error I get in clicking Details button shown in the image.. Here Connection.Json is my file in D:NetBonny which I use to access the data which consists of connections to database and some other settings which I require to run my project. NetBonny,netbonnyproject is my project name.

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\spool\DRIVERS\x64\3\Connection.Json'.
File name: 'C:\WINDOWS\system32\spool\DRIVERS\x64\3\Connection.Json'
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost)
   at System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost)
   at Microsoft.VisualBasic.MyServices.FileSystemProxy.ReadAllText(String file)
   at netbonnyproject.BonnyMdi.BonnyMdi_FormClosing(Object sender, FormClosingEventArgs e)
   at System.Windows.Forms.Form.OnFormClosing(FormClosingEventArgs e)
   at System.Windows.Forms.Form.WmClose(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
NetBonny
    Assembly Version: 1.0.0.102
    Win32 Version: 1.0.0.102
    CodeBase: file:///D:/Netbonny/NetBonny.exe
----------------------------------------
Microsoft.VisualBasic
    Assembly Version: 10.0.0.0
    Win32 Version: 14.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9261.0 built by: NET481REL1LAST_C
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9251.0 built by: NET481REL1LAST_C
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9214.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9214.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
MySql.Data
    Assembly Version: 8.0.28.0
    Win32 Version: 8.0.28.0
    CodeBase: file:///D:/Netbonny/MySql.Data.DLL
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
CrystalDecisions.CrystalReports.Engine
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.CrystalReports.Engine/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.CrystalReports.Engine.dll
----------------------------------------
CrystalDecisions.Shared
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.Shared/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.Shared.dll
----------------------------------------
CrystalDecisions.ReportAppServer.CommLayer
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.CommLayer/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CommLayer.dll
----------------------------------------
CrystalDecisions.ReportAppServer.ClientDoc
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.ClientDoc/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ClientDoc.dll
----------------------------------------
CrystalDecisions.ReportAppServer.DataDefModel
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.DataDefModel/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataDefModel.dll
----------------------------------------
CrystalDecisions.ReportAppServer.CubeDefModel
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.CubeDefModel/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CubeDefModel.dll
----------------------------------------
CrystalDecisions.ReportAppServer.ReportDefModel
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.ReportDefModel/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.ReportDefModel.dll
----------------------------------------
CrystalDecisions.ReportAppServer.Controllers
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.Controllers/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.Controllers.dll
----------------------------------------
CrystalDecisions.ReportAppServer.DataSetConversion
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.DataSetConversion/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.DataSetConversion.dll
----------------------------------------
System.Web
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
log4net
    Assembly Version: 2.0.12.0
    Win32 Version: 2.0.12.0
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/log4net/v4.0_2.0.12.0__669e0ddf0bb1aa2a/log4net.dll
----------------------------------------
CrystalDecisions.Shared.resources
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.Shared.resources/v4.0_13.0.4000.0_en_692fbea5521e1304/CrystalDecisions.Shared.resources.dll
----------------------------------------
Newtonsoft.Json
    Assembly Version: 13.0.0.0
    Win32 Version: 13.0.1.25517
    CodeBase: file:///D:/Netbonny/Newtonsoft.Json.DLL
----------------------------------------
System.Numerics
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Runtime.Serialization
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9241.0 built by: NET481REL1LAST_C
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
ToggleSwitch
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///D:/Netbonny/ToggleSwitch.DLL
----------------------------------------
CrystalDecisions.Windows.Forms
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.Windows.Forms/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.Windows.Forms.dll
----------------------------------------
System.Web.Services
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Web.Services/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.Services.dll
----------------------------------------
CustomMarshalers
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CustomMarshalers/v4.0_4.0.0.0__b03f5f7f11d50a3a/CustomMarshalers.dll
----------------------------------------
CrystalDecisions.ReportAppServer.XmlSerialize
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.XmlSerialize/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.XmlSerialize.dll
----------------------------------------
CrystalDecisions.ReportSource
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.ReportSource/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportSource.dll
----------------------------------------
CrystalDecisions.ReportAppServer.CommonObjectModel
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/CrystalDecisions.ReportAppServer.CommonObjectModel/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.ReportAppServer.CommonObjectModel.dll
----------------------------------------
CrystalDecisions.Windows.Forms.resources
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.Windows.Forms.resources/v4.0_13.0.4000.0_en_692fbea5521e1304/CrystalDecisions.Windows.Forms.resources.dll
----------------------------------------
CrystalDecisions.Web
    Assembly Version: 13.0.4000.0
    Win32 Version: 13.0.35.4870
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/CrystalDecisions.Web/v4.0_13.0.4000.0__692fbea5521e1304/CrystalDecisions.Web.dll
----------------------------------------
Syncfusion.SfInput.WinForms
    Assembly Version: 24.1460.41.0
    Win32 Version: 24.1460.41.0
    CodeBase: file:///D:/Netbonny/Syncfusion.SfInput.WinForms.DLL
----------------------------------------
Syncfusion.Shared.Base
    Assembly Version: 24.1460.41.0
    Win32 Version: 24.1460.41.0
    CodeBase: file:///D:/Netbonny/Syncfusion.Shared.Base.DLL
----------------------------------------
Syncfusion.Core.WinForms
    Assembly Version: 24.1460.41.0
    Win32 Version: 24.1460.41.0
    CodeBase: file:///D:/Netbonny/Syncfusion.Core.WinForms.DLL
----------------------------------------
Syncfusion.Tools.Windows
    Assembly Version: 24.1460.41.0
    Win32 Version: 24.1460.41.0
    CodeBase: file:///D:/Netbonny/Syncfusion.Tools.Windows.DLL
----------------------------------------
Accessibility
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Data.DataSetExtensions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.ValueTuple
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.ValueTuple/v4.0_4.0.0.0__cc7b13ffcd2ddd51/System.ValueTuple.dll
----------------------------------------
Snippets
    Assembly Version: 0.0.0.0
    Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
Anonymously Hosted DynamicMethods Assembly
    Assembly Version: 0.0.0.0
    Win32 Version: 4.8.9277.0 built by: NET481REL1LAST_B
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_64/mscorlib/v4.0_4.0.0.0__b77a5c561934e089/mscorlib.dll
----------------------------------------
System.Management
    Assembly Version: 4.0.0.0
    Win32 Version: 4.8.9032.0 built by: NET481REL1
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Management/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Management.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

Upvotes: 0

Views: 111

Answers (2)

Fawlty
Fawlty

Reputation: 497

Consider doing it one of these 2 ways instead. It's almost as if one of the assemblies in your app is interfering and overwriting the expected value.

METHOD 1 Use the code from METHOD 2 below to grab your path as soon as your app starts and store it to Settings. Reference the path stored in Settings in all other code.

METHOD 2

Dim appDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
Dim reportPath = Path.Combine(appDir, "Reports", "MyReport.rpt")
' Use reportPath for Crystal Reports processing

You could also try (in WinForms) Application.ExecutablePath

or

System.Reflection.Assembly.GetEntryAssembly().Location

Upvotes: 1

Fawlty
Fawlty

Reputation: 497

Now you have updated your Question, I can see this probably has nothing to do with your code. If MsgBox(FName) is showing YOUR path, then it can't possibly be your code trying to read the other path, because nothing can change the value of FName between your MsgBox and the line of code that tries to read the file.

  1. Please download ProcMon, https://learn.microsoft.com/en-us/sysinternals/downloads/procmon (from Microsoft)
  2. Then set a filter to capture events for the offending file / path.
  3. Double-click on the captured row to see which process is trying to access the file.

Try this for a start to see which information you can get.

ProcMon Filter

Upvotes: 0

Related Questions