C# 我在 SQL Server 复制项目中收到“尝试加载格式不正确的程序”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project
提问by baldy
The exact error is as follows
确切的错误如下
Could not load file or assembly 'Microsoft.SqlServer.Replication, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. An attempt was made to load a program with an incorrect format.
无法加载文件或程序集“Microsoft.SqlServer.Replication,版本=9.0.242.0,文化=中性,PublicKeyToken=89845dcd8080cc91”或其依赖项之一。试图加载格式不正确的程序。
I've recently started working on this project again after a two month move to another project. It worked perfectly before, and I've double checked all the references.
在转移到另一个项目两个月后,我最近又开始从事这个项目。它之前运行良好,我已经仔细检查了所有参考资料。
采纳答案by baldy
I've found the solution. I've recently upgraded my machine to Windows 2008 Server 64-bit. The SqlServer.Replication namespace was written for 32-bit platforms. All I needed to do to get it running again was to set the Target Platform in the Project Build Properties to X86.
我找到了解决方案。我最近将我的机器升级到 Windows 2008 Server 64 位。SqlServer.Replication 命名空间是为 32 位平台编写的。要让它再次运行,我所需要做的就是将 Project Build Properties 中的 Target Platform 设置为 X86。
回答by bboyle1234
The answer by baldybelow is correct, but you may also need to enable 32-bit applications in your AppPool.
下面baldy的回答是正确的,但您可能还需要在 AppPool 中启用 32 位应用程序。
来源:http: //www.alexjamesbrown.com/uncategorized/could-not-load-file-or-assembly-chilkatdotnet2-or-one-of-its-dependencies-an-attempt-was-made-to-load-格式不正确的程序/
Whilst setting up an application to run on my local machine (running Vista 64bit) I encountered this error:
在设置应用程序以在我的本地计算机(运行 Vista 64 位)上运行时,我遇到了以下错误:
Could not load file or assembly
ChilkatDotNet2
or one of its dependencies. An attempt was made to load a program with an incorrect format.
无法加载文件或程序集
ChilkatDotNet2
或其依赖项之一。试图加载格式不正确的程序。
Obviously, the application uses ChilKat components, but it would seem that the version we are using, is only the 32bit version.
显然,该应用程序使用了ChilKat 组件,但看起来我们使用的版本只是 32 位版本。
To resolve this error, I set my app pool in IIS to allow 32bit applications. Open up IIS Manager, right click on the app pool, and select Advanced Settings (See below)
为了解决这个错误,我在 IIS 中设置了我的应用程序池以允许 32 位应用程序。打开 IIS 管理器,右键单击应用程序池,然后选择高级设置(见下文)
Then set "Enable 32-bit Applications" to True.
然后将“启用 32 位应用程序”设置为 True。
All done!
全部完成!
回答by bboyle1234
Change the value for Platform Target on your web project's property page to Any CPU
.
将 Web 项目属性页上 Platform Target 的值更改为Any CPU
。
回答by Ryan Lundy
For those who get this error in an ASP.NET MVC 3project, within Visual Studio itself:
对于那些在ASP.NET MVC 3项目中遇到此错误的人,在 Visual Studio 本身中:
In an ASP.NET MVC 3 app I'm working on, I tried adding a reference to Microsoft.SqlServer.BatchParser to a project to resolve a problem where it was missing on a deployment server. (Our app uses SMO; the correct fix was to install SQL Server Native Client and a couple other things on the deployment server.)
在我正在处理的 ASP.NET MVC 3 应用程序中,我尝试向项目添加对 Microsoft.SqlServer.BatchParser 的引用,以解决部署服务器上缺少它的问题。(我们的应用程序使用 SMO;正确的解决方法是在部署服务器上安装 SQL Server Native Client 和其他一些东西。)
Even after I removed the reference to BatchParser, I kept getting the "An attempt was made..." error, referencing the BatchParser DLL, on every ASP.NET MVC 3 page I opened, and that error was followed by dozens of page parsing errors.
即使在我删除了对 BatchParser 的引用之后,我仍然在我打开的每个 ASP.NET MVC 3 页面上收到“尝试进行了...”错误,引用了 BatchParser DLL,并且该错误之后是数十个页面解析错误。
If this happens to you, do a file search and see if the DLL is still in one of your project's \bin folders.Even if you do a rebuild, Visual Studio doesn't necessarily clear out everything in all your \bin folders. When I deleted the DLL from the bin and built again, the error went away.
如果您遇到这种情况,请进行文件搜索并查看 DLL 是否仍在您项目的 \bin 文件夹之一中。即使您进行了重建,Visual Studio 也不一定会清除所有 \bin 文件夹中的所有内容。当我从 bin 中删除 DLL 并再次构建时,错误消失了。
回答by Harpal
Go to IIS -> Application Pool -> Advance Settings -> Enable 32-bit Applications
转到 IIS -> 应用程序池 -> 高级设置 -> 启用 32 位应用程序
回答by SushiGuy
If Publishing in Visual Studio 2012when erroring try unchecking the "Procompile during publishing"option in the Publish wizard.
如果在 Visual Studio 2012 中发布时出错,请尝试取消选中发布向导中的“发布期间进行Procompile”选项。
回答by Justin
We recently had the issue when trying to run the code from Visual Studio. In that case you need to do
TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS and check the "Use the 64 bit version of IIS Express for web sites and projects".
我们最近在尝试从 Visual Studio 运行代码时遇到了问题。在这种情况下,您需要执行
TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS 并选中“为网站和项目使用 64 位版本的 IIS Express”。
回答by munwar shaiik
change it to 32-bit (true) it works
将其更改为 32 位(真)它可以工作
if you get this Length cannot be less than zero. Parameter name: length issue in iis server configuation do the simple thing change the connection string in web.config file like your sql server name and server name and restart iis then try to load the page it works
如果你得到这个长度不能小于零。参数名称:iis 服务器配置中的长度问题 做简单的事情更改 web.config 文件中的连接字符串,如您的 sql 服务器名称和服务器名称,然后重新启动 iis 然后尝试加载它工作的页面
回答by Amirhossein Yari
in windows form application I do this, Right-click on Project->Properties->Build->Check Prefer 32-bit checkbox. Thanks all
在 Windows 窗体应用程序中,我这样做,右键单击 Project->Properties->Build->Check Prefer 32-bit 复选框。谢谢大家
回答by Madhurya Gandi
Delete the temp test directory located here C:\Users(User)\AppData\Local\Temp\VisualStudioTestExplorerExtensions\
Set all projects to x64 in Visual Studio
Set the default processor architecture to x64(Test/TestSettings/Default Processor Architecture).
删除位于 C:\Users(User)\AppData\Local\Temp\VisualStudioTestExplorerExtensions\ 的临时测试目录
在 Visual Studio 中将所有项目设置为 x64
将默认处理器架构设置为 x64(测试/测试设置/默认处理器架构)。
Make sure to clean build the solution file.Hope this helps!
确保清理构建解决方案文件。希望这会有所帮助!