We have a .NET dll "A" that is created by a third party. It exposes classes through a tlb to our VB6 exe application.
We also have our own .NET dll "B" that references .NET dll "A". "B" also exposes classes to our VB6 exe application through a tlb.
Now, the VB6 application has no problem using classes from either library in the VB6 code until we try to call a function in "B" that has a parameter type from "A". In that case, we get an error 430 or an error saying "unable to cast com object of type 'system.__comobject' to type 'Type.From.Dll.A'"
What could be causing this? Is this normal?
You problem is the different NET versions as you said.
In version 4 , the NET team introduced the In-Process Side-by-Side Execution
With this you can have different versions of the CLR running in your application.
But that is not what you want, so I think you should turn this feature off, using an app.config file:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Please note, that while you are using the VB6 IDE, the process that requires an app.config is the VB6.exe, so I would also copy that app.config to the VB6 folder and renamed it as VB6.exe.config. See this answer
Related
I am making a new ASP.NET Core 2.0 project, essentially a Web API. I have to reference several assemblies that are .NET 3.5 assemblies, so I am running this as a .NET Framework project, just using the .NET Core improvements where possible.
The referenced .NET framework 3.5 assembly references TaskParallelLibrary (1.0.2856). And I think that's where my issues are coming in. It's worth noting the Web API worked on its sample endpoints and all worked as expected.
When I run the application and try and use the referenced library, the call fails and I receive the following exception:
Could not load file or assembly 'System.Threading, Version=1.0.2856.102, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
or one of its dependencies. The system cannot find the file specified.
I have tried several things, including:
Adding an App.configx file to try and force it to target .NET framework 4's System.Threading, on the assumption that that will be available. Inspired by a page I can't find the link for:
Here's the content:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- this is only here for binding redirects -->
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Directly adding the TaskTPLLibrary package at that version to the project. So far, it hasn't helped.
Adding the Microsoft.Bcl.Async library to my project. Again, nothing.
Trying to directly import System.Threading from "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Threading.dll". I get an error stating "The reference is invalid or unsupported."
I've tried several other things, including re-cloning, cleaning, re-cleaning, swearing vociferously and coming back at it another day, all to no avail.
My reading list includes (on this computer):
https://github.com/dotnet/corefx/issues/26084
Could not load file or assembly System.Threading.Tasks, Version=2.5.19.0
ASP.NET Core 2.0 Site - FileIOException System.Runtime
And probably others that I can't remember
Some additional information as this issue continues:
Creating a .NET Framework ASP.NET MVC app using .NET Framework 4.6.2 with the same underlying library does work. It does it indirectly using an intermediary .NET Framework 3.5 one (just for convenience as much as anything else).
A .NET Framework 4.6.2 Console App that uses the library directly also runs into this problem. So it seems not to be ASP.NET Core itself. I'll change the tags accordingly.
Making the 4.6.2 console use the intermediary 3.5 library doesn't resolve the issue.
Any help in resolving this issue much appreciated.
As there's no reasonable answer forthcoming, I'm assuming that having a .NET 3.5 Framework library referenced that uses the TaskParallelLibrary will in essence mean that using any .NET above 4 will cause this error. Under unspecified conditions. Most of the time.
The only solution to this seems to be rewrite everything to multi-target .NET 3.5 and .NET Standard and have the Standard implementation use the real TPL and have the 3.5 one use the NuGet package.
I'm having a project which is to add new features to a VB6 application. In order to migrate the application to the more advanced technology incrementally, we choose to use VB Interop technology. However, we found that the VB Interop Form is actually based on .Net 2.0. So, I'm asking how can we use higher version of the .Net framework?
thanks
Short answer is no, but stable in 3.5 framework. Microsoft is aware of the issue, but can't tell you when there would be a fix. You can find more here.
Another good read here.
Interop Forms Toolkit can be used with .NET 4.0. I have been using it for more than 6 months with no problems.
The problem discussed here is due to In-Process Side-by-Side Execution, introduced in .NET 4. With this you can have different versions of the CLR running in your application. This can be fixed by using an app.config file:
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
I answered a similar problem here, and here
I am trying to access a VB.NET DLL (.NET FX 4.0) from a VB6 client in a reg-free scenario.
I tried to follow the example from http://msdn.microsoft.com/en-us/library/ms973915.aspx, but with no success. I downloaded (link in the article) the sources and compiled, no success (error message: Run-time error '-2146234341 (8013101b)': Automation error"). Running from VB6 IDE using registered VB.NET DLL works.
I tried other examples where the .NET DLL is created as a COM Class (using "COM Class" template from VS2010), with manifest for referenced DLL embedded or not, but nothing worked for me.
Can somebody provide some simple source code with manifests example of VB.NET DLL (.NET FX v4) used in VB6 client in reg-free scenario?
Thanks much in advance.
Run-time error '-2146234341 (8013101b)': Automation error
Your problem doesn't have anything to do with a manifest, you'll need to fix this one first. The error code is COR_E_NEWER_RUNTIME. In other words, your [ComVisible] class cannot be loaded because it depends on CLR version 4. And the program has already loaded the CLR, version 2 most likely, because another [ComVisible] class asked first. And it asked for version 2.
You'll need an app.exe.config file that forces CLR version 4 to get loaded, even when somebody asks for version 2. It should look like this:
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
Give it the same name as the vb6 exe (like "foo.exe.config" to match "foo.exe") and put it in the same directory as the .exe. If you want to use the VB6 IDE to debug your vb6 code that uses this library then you also need vb6.exe.config in c:\program files\microsoft visual studio\vb98
I'm trying to write a c# custom action and using .Net 2, however I can't seem to get things to work. I believe the MSI is using the wrong CLR version. I see this in the log file a few lines above where the MSI is calling my CA (line line does not appear if I comment out my CA):
SFXCA: Binding to CLR version v4.0.30319.
My custom action does not appears to load (assuming since I do not see any of the logging messages). I am using Wiz 3.6.3014.0. Is this supported or does the Windows Installer just use the latest runtime available on the machine?
Thanks
When you use WiX to create a C# custom action project, it by default creates an XML file called CustomAction.config. The purpose of this file is to instruct sfxca.dll what version of the CLR to use when running your code. The default implementation of this file looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--
Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
the custom action should run on. If no versions are specified, the chosen version of the runtime
will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.
WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
only the version(s) of the .NET Framework runtime that you have tested against.
Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.
In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
by using the latest supported runtime, #useLegacyV2RuntimeActivationPolicy="true".
For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
-->
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727"/>
</startup>
<!--
Add additional configuration settings here. For more information on application config files,
see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->
</configuration>
Basically it's a good practice for CA's written in .NET 2.0/3.0/3.5 ( all CLR 2.0 ) to be allowed to run against 4.0 because you could come across a machine that has only 4.0 installed. Generally your code should work against 4.0 and if it doesn't, I'd fix that.
Alternatively you could update the config file to only allow running on 2.0 and then put the needed checks into the installer to make sure that this version of the CLR is infact installed.
I tried to use NHibernate with SQLite,
version=1.0.74.0 for .NET 4 and 32 bit.
I use a 64bit WIN7, but build the application in x86 mode
(default in VS2010 express).
When I use the same SQLite as a standalone application it works fine, but when
I try to use it with NHibernate it throws BadImageFormatExcepion
I debugged a bit NHibernate and the Exception is thrown at the folllowing statement
System.Type.GetType("System.Data.SQLite.SQLiteConnection, System.Data.SQLite");
Any chances somebody knows the solution?
Is it because I use default mode in VS Express?
Do I need to specify platform using some other method?
try to download some other dll for sqlite?
I checked some other answers on SO thebest I got was
to add to my app.config this:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"/>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
</DbProviderFactories>
</system.data>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
If VS express does not allow you to choose a platform you can try setting it up manually in .csproj file
<PlatformTarget>x86</PlatformTarget>
After building your app make sure that:
it is executed as 32 or 64 bit app depending on what you put in PlatformTarget (using Windows Task Manager or Process Explorer)
the right version of SQLite.Interop.dll is copied to the folder where you have your exe (this dll is platform dependent, so you need to copy the version corresponding to EXE platform)
Corresponding version of Visual C++ 2010 SP1 Redistributable Package is installed
Also try removing useLegacyV2RuntimeActivationPolicy from config.
From BadImageFormatException doc:
... A DLL or executable is loaded as a 64-bit assembly, but it contains
32-bit features or resources. For example, it relies on COM interop or
calls methods in a 32-bit dynamic link library. ... To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.