我刚刚创建了一个wcf服务库,并使用一个简单的控制台应用程序连接到它。但是,当我启动控制台应用程序时,wcf服务主机打开并显示以下错误:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\uop\source\repos\WPF\APPONE\APPONE.Service\bin\x86\Debug\APPONE.Service.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Users\amosa\source\repos\WPF\APPONE\APPONE.Service\bin\x86\Debug\APPONE.Service.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].我已经确保我的所有应用程序都在运行x86。
我试着看看这是不是我的程序中的一个问题,但它甚至没有达到我的程序中的第一个调试点:
static void Main(string[] args)
{
// Step 1: Create a URI to serve as the base address.
Uri baseAddress = new Uri("http://localhost:8733/APPONE/");
// Step 2: Create a ServiceHost instance.
ServiceHost selfHost = new ServiceHost(typeof(DocumentType), baseAddress);
try
{
selfHost.AddServiceEndpoint(typeof(IDocumentType), new WSHttpBinding(), "DocumentType");
// Step 4: Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5: Start the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
// Close the ServiceHost to stop the service.
Console.WriteLine("Press <Enter> to terminate the service.");
Console.WriteLine();
Console.ReadLine();
selfHost.Close();
}
catch(Exception e)
{
Console.WriteLine("An exception occurred: {0}", e.Message);
selfHost.Abort();
}
}发布于 2020-06-19 10:41:42
根据您的描述,我做了test.First,您需要将平台目标值设置为“任何CPU":

然后将项目构建为可执行文件,并以管理员身份运行:

另外,我使用的.Net框架是4.7.2。实际上,如果你在VS中使用x86调试,你会得到上面的错误,你直接将项目构建成一个可执行文件,然后以管理员身份运行它,这是可以的。
https://stackoverflow.com/questions/62446725
复制相似问题