C# 读取配置文件不需要';我不能在另一台计算机上工作

C# 读取配置文件不需要';我不能在另一台计算机上工作,c#,.net,app-config,windows-applications,C#,.net,App Config,Windows Applications,我正在用c#制作windows应用程序。我在.NET framework 3.5中制作了一个应用程序,我使用的是windows vista。当我构建该应用程序并尝试在其他使用windows 7的机器上运行时,它不工作。目标计算机在控制面板中显示.NET framework 4.0客户端配置文件。每当我试图从配置文件中读取某些值时,就会出现此问题。如果我不使用配置文件,则我的应用程序会运行,但我必须使用配置文件。 为了检查框架问题,我制作了一个简单的应用程序,在这个应用程序中,我试图通过单击按钮读

我正在用c#制作windows应用程序。我在.NET framework 3.5中制作了一个应用程序,我使用的是windows vista。当我构建该应用程序并尝试在其他使用windows 7的机器上运行时,它不工作。目标计算机在控制面板中显示.NET framework 4.0客户端配置文件。每当我试图从配置文件中读取某些值时,就会出现此问题。如果我不使用配置文件,则我的应用程序会运行,但我必须使用配置文件。 为了检查框架问题,我制作了一个简单的应用程序,在这个应用程序中,我试图通过单击按钮读取配置文件值,如
MessageBox.Show(ConfigurationManager.AppSettings[“FlagForArchiving”].ToString())
但我也有错误

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

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at TestFramework.Form1.button1_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(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.0.30319.239 (RTMGDR.030319-2300)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
TestFramework
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Users/mvi/AppData/Local/Temp/Temp1_test.zip/Release/TestFramework.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.235 built by: RTMGDR
    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.0.30319.1 built by: RTMRel
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.236 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.1 (RTMRel.030319-0100)
    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.0.30319.233 built by: RTMGDR
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.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.
有关调用的详细信息,请参阅此消息的结尾
即时(JIT)调试,而不是此对话框。
**************例外文本**************
System.NullReferenceException:对象引用未设置为对象的实例。
在TestFramework.Form1.button1\单击(对象发送者,事件参数e)
在System.Windows.Forms.Control.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnClick(EventArgs e)中
在System.Windows.Forms.Button.OnMouseUp(MouseEventArgs-mevent)上
在System.Windows.Forms.Control.WmMouseUp(Message&m、MouseButtons按钮、Int32单击)
位于System.Windows.Forms.Control.WndProc(Message&m)
位于System.Windows.Forms.ButtonBase.WndProc(Message&m)
在System.Windows.Forms.Button.WndProc(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)中
在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)中
在System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd、Int32 msg、IntPtr wparam、IntPtr lparam)中
**************加载的程序集**************
mscorlib
程序集版本:4.0.0.0
Win32版本:4.0.30319.239(RTMGDR.030319-2300)
代码库:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
测试框架
程序集版本:1.0.0.0
Win32版本:1.0.0.0
代码库:file:///C:/Users/mvi/AppData/Local/Temp/Temp1_test.zip/Release/TestFramework.exe
----------------------------------------
System.Windows.Forms
程序集版本:4.0.0.0
Win32版本:4.0.30319.235生成者:RTMGDR
代码库:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
系统图
程序集版本:4.0.0.0
Win32版本:4.0.30319.1生成者:RTMRel
代码库:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
系统
程序集版本:4.0.0.0
Win32版本:4.0.30319.236生成者:RTMGDR
代码库:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
系统配置
程序集版本:4.0.0.0
Win32版本:4.0.30319.1(RTMRel.030319-0100)
代码库:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
命名空间
程序集版本:4.0.0.0
Win32版本:4.0.30319.233生成者:RTMGDR
代码库:file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
**************JIT调试**************
要启用即时(JIT)调试,请为
应用程序或计算机(machine.config)必须具有
在system.windows.forms节中设置的值。
应用程序还必须通过调试进行编译
启用。
例如:
启用JIT调试时,任何未处理的异常
将发送到计算机上注册的JIT调试器
而不是由此对话框处理。

请帮我解决我的问题。提前谢谢。

可能是因为目录访问。通过管理员运行应用程序以保证访问。

将配置文件更改为“.NET Framework 3.5”。“.NET Framework 3.5客户端配置文件”有几个限制,不会提供您可能需要的所有程序集。

FileNotFoundException
表示配置文件不在您的应用程序文件夹中。确保在发布应用程序时部署了配置文件


是的,安装应用程序的每台计算机上都需要一个配置文件。

是否将配置文件复制到另一台计算机上?你得到了什么错误?你能写下准确的错误日志,以便我们调查吗?@zmbq:在构建该应用程序后,是否需要将配置文件单独复制到其他机器上?我的配置文件有一些值,每当我试图运行我的应用程序时,它给出的错误是FileNotFoundExceptionies,您需要将配置文件复制到另一台机器上。检查@Otiel的答案。谢谢,但我的目标机器有windows 7,我认为在windows 7中已经安装了.NET framework 3.5。@Dany,但你说过,windows 7机器在控制面板中显示了.NET framework 4.0客户端配置文件。这可能不包含使用“.NET Framework 3.5”配置文件构建应用程序时所需的部分。它在控制面板中仅显示.NET Framework 4.0客户端配置文件,而不显示.NET Framework 3。5@Dany因此,该机器上可能安装了错误的.NET Framework。