I can't compile a standard "WCF Service Library" in x86 format - wcf

If I start up Microsoft Visual Studio, create a standard "WCF Service Library", and compile it, it works perfectly.
However, if I go into Properties..Build and set the "Platform Target" to "x86", it won't compile. I need "x86" because I need to reference some .dll's that simply won't work if I choose "All Platforms".
-----start error-----
System.BadImageFormatException: Could not load file or assembly 'file:///D:\backtest\C#\WCF service\WcfServiceLibrary\bin\Debug\WcfServiceLibrary.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///D:\backtest\C#\WCF service for\WcfServiceLibrary\bin\Debug\WcfServiceLibrary.dll'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
=== Pre-bind state information ===
LOG: User = dr-satellite\Shane
LOG: Where-ref bind. Location = D:\backtest\C#\WCF service for\WcfServiceLibrary\bin\Debug\WcfServiceLibrary.dll
LOG: Appbase = file:///D:/backtest/C#/WCF service for/WcfServiceLibrary/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: D:\backtest\C#\WCF service for\WcfServiceLibrary\bin\Debug\WcfServiceLibrary.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///D:/backtest/C#/WCF service for/WcfServiceLibrary/bin/Debug/WcfServiceLibrary.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
-----end error-----

Your problem is actually the WCF Test Client complaining that your WCF Service Library is 32bit. This is because by default, the WCF Test Client always runs in 64 bit mode.
Rather than going to the lengths of changing to a WCF Service Application so you can debug, I found the following steps on this blog which makes the WCF Test Client run in 32bit mode - and therefore you will not see the error you have posted.
Copy WcfSvcHost.exe and WcfTestClient.exe from C:\program files (x86)\Microsoft Visual Studio 10.0\Common7\IDE to a local directory. Keep a backup copy of this file, of course.
Start a Visual Studio 2010 Command Prompt (one of the links from the start menu -> Visaul Studio 2010)
"cd" to the directory where your copy of WcfSvcHost is located.
Execute the command "corflags /32BIT+ /FORCE WcfSvcHost.exe"
Execute the command "corflags /32BIT+ /FORCE WcfTestClient"
Copy the files back to where you found it.
Now your WcfSvcHost and WcfTestClient will be running in 32 bit mode, and you can debug away!

I found two good methods to solve this:
Installing the 64-bit version of Matlab means you can compile 64-bit .dll's which are compatible with the 64-bit WCF Service Library. This removes the need to compile in 32-bit mode so it doesn't throw exceptions when it calls the 32-bit assembly. This solution works well.
There are two types of projects you can generate in MSVS 2010: "WCF Service Library" and "WCF Service Application". Although you cannot build and run a "WCF Service Library" in 32-bit mode (it only supports 64-bit), you can build and run a "WCF Service Application" in 32-bit mode.

Related

Running dotnet ef without Visual Studio throws an exception

I have a project that is a .NET Core console application with just a model and some seed data. On a development desktop I can go to the application directory, run dotnet ef database update and everything is fine (I need to copy appsettings.json to bin\... directory, but OK).
The problem is when I need to run this in the client environment (with VPN access, and without Visual Studio there). First, I am not sure what exactly I need to copy to the remote machine. But let's say, I copied the whole project. First, when I run, I get the following error:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools'.
I have a directory .nuget\packages\Microsoft.EntityFrameworkCore.Tools but not under .tools. Out of despair I created .tools and copied this directory under it, but now I am getting the following exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromToolLibrary(LibraryRange toolLibraryRange, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromAllToolLibraries(IEnumerable`1 toolsLibraries, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveFromProjectTools(String commandName, IEnumerable`1 args, String projectDirectory)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CompositeCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CommandResolver.TryResolveCommandSpec(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Utils.Command.Create(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
Clearly, my trial and error attempts to find the right way hit a wall. Is there some substantive (not just syntax) documentation as to how to run EF Core commands outside Visual Studio? .NET is version 1.1 if that matters
It seems that you have not removed Entity framework completly hence the error that path: .nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools is not found.
Somewhere in code there must be a reference to this file. If you are using project.json try checking your tools and depenedencies for Microsoft.EntityFrameworkCore.Tools.
If you are using the .csproj SDK version. Check your project file for any of these references and remove them.

Assembly.LoadFrom doesn't load dll from bin\debug when running unit tests with resharper

I am using VS 2015 Update 2 with Resharper Ultimate 2016.1 and I have this weird issue.
I have a test project called Test which references two projects, Model and Persistence. The model project contains nhibernate entity classes and the Persistence project contains *.hbm.xml files. They were generated with llblgenpro 4.2. I am using nhibernate 4.0.4.
I initialize NHibernate with this call:
NHibernateSession.Init(
new SimpleSessionStorage(),
new string[] { "Persistence.dll", "Model.dll" });
When I run one of my test cases the nhibernate initialization fails with this exception:
System.IO.FileNotFoundException was unhandled by user code
FileName=file:///C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll
FusionLog==== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll
LOG: Appbase = file:///C:/projects/csharp/Test/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\costa\AppData\Local\Temp\s0hjyhsk.jq1\a3514fde-acb9-4c62-a0ce-a586f8202f35.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/Users/costa/AppData/Local/JetBrains/Installations/ReSharperPlatformVs14/Persistence.dll.
HResult=-2147024894
Message=Could not load file or assembly 'file:///C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14\Persistence.dll' or one of its dependencies. The system cannot find the file specified.
Source=mscorlib
StackTrace:
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.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at SharpArch.NHibernate.NHibernateSession.<>c__DisplayClass36_0.<CreateSessionFactoryFor>b__0(MappingConfiguration m) in C:\work\sharp-arch\Solutions\SharpArch.NHibernate\NHibernateSession.cs:line 412
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
InnerException:
If I copy the persistence.dll to the C:\Users\costa\AppData\Local\JetBrains\Installations\ReSharperPlatformVs14 folder, the test case works fine. persistence.dll is in the C:/projects/csharp/Test/bin/Debug folder because the persistence project is referenced in the test project.
This all worked fine in VS 2013 with nhibernate 3.3.1. Also I got all the dll versions to align using the assemblybinding elements in the test project app.config file.
My projects target .Net 4.6 and I use nunit 3.2.1.
I found this:
Resharper runs UnitTest from different location
However, in my case 'Shadow-copy assemblies being tested' is turned off, Use separate AppDomain for each assembly with tests is also turned off. Run Tests from is set to Project output folder.
Any ideas what could cause this?
Thanks
An update: If I do this it works:
string path = Assembly.GetExecutingAssembly().Location;
string directory = Path.GetDirectoryName(path);
NHibernateSession.Init(
new SimpleSessionStorage(),
new string[] { directory + "\\Persistence.dll", directory + "\\Model.dll" });
Update 2. My project uses the Sharp Architecture library. NHibernateSession is a class that belongs to this library.
This is likely a change in NUnit 3, which no longer changes the current directory to the location of the assembly under test. I believe this is because it can run multiple assemblies in a single test run - so which directory would be best?
As per the NUnit 3 Breaking Changes document, you can use TestContext.CurrentContext.TestDirectory to locate the directory that contains the assembly under test.

Autocad .net framework 32 bits selection

Gents,
I was wondering if there is any way to configure the autocad.exe.config file so it works with the 32 bits version of .net framework.
I'm developing an application for autocad 2008 32 bits in a 64 bits machine (windows 7) that gets some data from an access database (32 bits) therefore I'm getting the infamous "'microsoft.ace.oledb.12.0' provider is not registered on the local machine" error.
Looking for a solution I've found that the only way to solve this is to target x86 machine in VS, but Autocad can't load the application because is reading the .net configuration from framework64 folder.
Update:
This is the error I get in the autocad command line when the x86 application is loaded:
Cannot load assembly. Error details: System.BadImageFormatException: Could not
load file or assembly
'file:///C:\#Documentos\Personales\CODING\AutoCad\vb.net\OleDBTest\ClassLibrary1
\bin\Debug\ClassLibrary1.dll' or one of its dependencies. An attempt was made
to load a program with an incorrect format.
File name:
'file:///C:\#Documentos\Personales\CODING\AutoCad\vb.net\OleDBTest\ClassLibrary1
\bin\Debug\ClassLibrary1.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()
=== Pre-bind state information ===
LOG: User = GLOBAL\rodrigo.cortes
LOG: Where-ref bind. Location =
C:\#Documentos\Personales\CODING\AutoCad\vb.net\OleDBTest\ClassLibrary1\bin\Debu
g\ClassLibrary1.dll
LOG: Appbase = file:///C:/Program Files/AutoCAD 2008/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will
only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Program Files\AutoCAD
2008\acad.exe.Config
LOG: Using machine configuration file from
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Attempting download of new URL
file:///C:/#Documentos/Personales/CODING/AutoCad/vb.net/OleDBTest/ClassLibrary1/
bin/Debug/ClassLibrary1.dll.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.

Publish ClickOnce installation error "Exception reading from manifest" using VB.NET

I'm using Visual Studio 2010 and VB.NET. My target environment is .NET Framework 4.0.
So I'm facing this problem when I'm publishing my project by using the provided Setup.exe file. After the verifying application requirement popped up, an alert popped up with text:
Cannot Continue. The application is improperly formatted. Contact the application vendor for assistance.
When I clicked on the "Detail" button, it showed me this error:
PLATFORM VERSION INFO
Windows : 6.1.7601.65536 (Win32NT)
Common Language Runtime : 4.0.30319.239
System.Deployment.dll : 4.0.30319.1 (RTMRel.030319-0100)
clr.dll : 4.0.30319.239 (RTMGDR.030319-2300)
dfdll.dll : 4.0.30319.1 (RTMRel.030319-0100)
dfshim.dll : 4.0.31106.0 (Main.031106-0000)
SOURCES
Deployment URL : file:///I:/ProjectBMTRelease/ProjectBMT.application
IDENTITIES
Deployment Identity : ProjectBMT.application, Version=1.0.0.6, Culture=neutral, PublicKeyToken=7439f62500c0364d, processorArchitecture=x86
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of I:\ProjectBMTRelease\ProjectBMT.application resulted in exception. Following failure messages were detected:
+ Exception reading manifest from file:///I:/ProjectBMTRelease/Application%20Files/ProjectBMT_1_0_0_6/ProjectBMT.exe.manifest: the manifest may not be valid or the file could not be opened.
+ Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed:
-HRESULT: 0x80070c81
Start line: 0
Start column: 0
Host file:
+ Exception from HRESULT: 0x80070C81
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [6/23/2012 5:21:36 PM] : Activation of I:\ProjectBMTRelease\ProjectBMT.application has started.
* [6/23/2012 5:21:36 PM] : Processing of deployment manifest has successfully completed.
* [6/23/2012 5:21:36 PM] : Installation of the application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [6/23/2012 5:21:36 PM] System.Deployment.Application.InvalidDeploymentException (ManifestParse)
- Exception reading manifest from file:///I:/ProjectBMTRelease/Application%20Files/ProjectBMT_1_0_0_6/ProjectBMT.exe.manifest: the manifest may not be valid or the file could not be opened.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Deployment.Application.InvalidDeploymentException (ManifestParse)
- Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed:
-HRESULT: 0x80070c81
Start line: 0
Start column: 0
Host file:
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)
at System.Deployment.Application.Manifest.AssemblyManifest..ctor(FileStream fileStream)
at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
--- Inner Exception ---
System.Runtime.InteropServices.COMException
- Exception from HRESULT: 0x80070C81
- Source: System.Deployment
- Stack trace:
at System.Deployment.Internal.Isolation.IsolationInterop.CreateCMSFromXml(Byte[] buffer, UInt32 bufferSize, IManifestParseErrorCallback Callback, Guid& riid)
at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
I checked my project's manifest file, but I am not good enough to find any problem there. For other information, I created simple "Hello World !" application to see if it will get published well, and it did.
What is the solution?
Check the following:
Does the user have .NET 4 installed on their computer?
How are you publishing the application, are you using Visual Studio?
Are you making any changes to the deployment after publishing it?
If you are manually moving the files to the deployment location, is the structure identical to the original structure?
Try enabling detailed logging and see if that provides more information. The
article Enhanced Logging in ClickOnce Deployment shows you how to do that.
I got this very same error. The problem got resolved after I renamed my assembly name found on the first tab under application properties. It seems like having an assembly name with a space creates a manifest filename with a blank space and it seems to create problems. My application assembly name was named "Capital Manager". After I changed it to "Capital_Manager" (I replaced the space with an under score "_") the issue got resolved.
I received an error report and call stack pretty much identical to yours when attempting to run the ClickOnce installer. My findings so far may be helpful to others arriving here, so I'll post the details, but I have a feeling this same error report may be caused by a range of different problems.
The first thing I noticed was that my application manifest (the one that lists all of the files for the application + a signature hash for each) had entries for assemblies that had an invalid publicKeyToken, for example,
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1">
<asmv1:assemblyIdentity name="foo.exe" version="1.2.3.4" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
Further down the file instead of seeing dependentAssembly elements for assemblies some of the assemblies were listed as plain content files (file elements).
These problems certainly make the ClickOnce deployment invalid, and the cause was using a version of Mage that was compiled against an older version of .NET than the assemblies it was trying to create manifests for. When creating the application manifest Mage will attempt to read assemblies as follows:
AssemblyIdentity.FromFile(fileName);
And for Mage compiled against .NET 3.5 (CLR 2.0) trying to load a .NET 4.0 assembly results in a BadImageFormatException exception which is handled, and the fall-back behaviour is to treat these files as content files.
Does your application folder have subfolders? I got this same HRESULT just yesterday, and the root cause was that a library (EntityFramework.dll) was in both the top level and in a subfolder. (There was a MAGE warning about this, but it was not handled as an error.) I updated my script to remove EntityFramework.dll from the subfolder, and the ClickOnce is fine now.
Just another possibility - I got a similar error when adding a dpiAware to a newly created app.manifest file. ClickOnce started failing immediately.
I followed the advise here: Installing ClickOnce published DPI-aware application
So if you've been doing dpi things, maybe look there.

Upgrading App from .NET 3.5 to 4.0, COM fails now

I have an application that I am upgrading from the .NET 3.5 to the .NET 4.0 framework. It uses a COM library which is referenced. It works no problem in 3.5 but after converting to 4.0 I have issues getting the COM to work. The COM is from a 3rd party so we didn't develop it ourselves.
I get the following COM error (generic COM error, not specific to the COM object itself): hr = 0x8007000b
CLR gives me: 'The invocation of the constructor on type 'Skype_Business_Launcher.Main' that matches the specified binding constraints threw an exception.' Line number '3' and line position '5'.
And the C# logs:
=== Pre-bind state information ===
LOG: User = \phillip
LOG: DisplayName = Interop.SKYPE4COMLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
(Fully-specified)
LOG: Appbase = file:///bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Skype Business Launcher, Version=1.0.5.0, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file:
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///bin/Debug/Interop.SKYPE4COMLib.DLL.
ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
I removed the pathname for security reasons but I have checked all the path information and it's all correct. Also the COM library file exists where it's pointing to. It's also copied to the OBJ folder within the project as well.
Originally I was getting an error about the COM library not supporting embedded types so I made "Embed Interop Types" false (it was true below) and the error went away but I'm not sure if thats connected to this error or not so I thought I'd mention it just in case.
Again, it works just fine with 3.5.
Thanks,
A shot in the dark: it looks like you are using the x64 version of the framework. Was that already the case with 3.5 ? And is the COM server a DLL or an EXE ?
If the COM server is a DLL, there needs to be a "bitness" match between the DLL and your program.
when you convert your project to 4.0 the IDE can perform a issue to convert COM library into 4.0.
when you convert your project to 4.0 remove com library then Re include it in your project then i thing it should be works.