MissingMethodException when running application on different computer - app-config

I have a problem where I compiled my application on Visual Studio 2010 while targetting the .NET Framework 3.5, deployed it to a client server, only to find it gives me the following error:
************** Exception Text **************
System.MissingMethodException: Method not found: 'Void
System.Xml.Xsl.XslCompiledTransform.Transform(
System.Xml.XPath.IXPathNavigable,
System.Xml.Xsl.XsltArgumentList,
System.Xml.XmlWriter,
System.Xml.XmlResolver)'.
************** Loaded Assemblies **************
[...]
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.3082 (QFE.050727-3000)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
The method it says it's looking for is this: XslTransform.Transform Method (IXPathNavigable, XsltArgumentList, XmlWriter, XmlResolver) (Supported in: 4, 3.5, 3.0, 2.0, 1.1)
I've tried setting up a redirect to the .NET Framework 4.0 version of the same DLL using the assemblyBinding element like so:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Xml"
publicKeyToken="b77a5c561934e089"
culture="neutral" />
<bindingRedirect oldVersion="2.0.0.0"
newVersion="4.0.0.0"/>
<codeBase version="4.0.0.0"
href="file:///C:/WINDOWS/Microsoft.NET/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But now the application won't run, and puts this in the event log:
EventType clr20r3, P1
myapplication.exe, P2 3.85.12.27583,
P3 4be9757f, P4 system.configuration,
P5 2.0.0.0, P6 4889de74, P7 1a6, P8
136, P9
ioibmurhynrxkw0zxkyrvfn0boyyufow, P10
NIL.
So, in summary, (1) does anyone know why the application can't find the method listed, and (2) why doesn't it let me redirect to the .NET 4.0 version of System.Xml?
Any help is appreciated, I'm totally stuck!
app.config as requested:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="myapplication.Properties.UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<system.net>
<mailSettings>
<smtp from="e-monitoring#myapplication.co.uk">
<network defaultCredentials="true" host="192.168.0.132" port="25" password="" userName="" />
</smtp>
</mailSettings>
</system.net>
<appSettings file="">
<add key="ReportDataCollectionTimeout" value="360" />
<add key="AllowedDatabaseBuild" value="3" />
<add key="AllowedDatabaseRevision" value="085" />
<add key="HelpNamespace" value="myapplicationHelpfile.chm" />
<add key="ProFormaHomePageUri" value="https://myapplication.co.uk/" />
<add key="ProFormaLoginPageUri" value="https://myapplication.co.uk/login.aspx" />
</appSettings>
<connectionStrings configSource="connectionStrings.config" />
<userSettings>
<myapplication.Properties.UserSettings>
<setting name="RequiresUpgrade" serializeAs="String">
<value>True</value>
</setting>
</myapplication.Properties.UserSettings>
</userSettings>
</configuration>

If you are targeting .NET 3.5 why are you doing a binding redirect to System.Xml v4.0.0.0? Make sure that your project references v2.0.0.0 of that assembly and that you have the following in your app.config:
<startup><supportedRuntime version="v2.0.50727"/></startup>
Also make sure that you are targeting .NET Framework 3.5 and not .NET Framework 3.5 Client Profile. Finally make sure the client has .NET 3.5 installed.

I've solved the problem by using this Transform method instead of the previous one (where I was previously passing null into the XmlResolver argument at the end).
Strange how this worked on my development and test machine, and not the server.

Try looking into the file version for System.XML.dll in the assembly folder. chances are that the last bit of the file on your system are different then the ones on server. in your case "2.0.50727.3082" does not seem to have the specified method signature. The version on the development machine was "2.0.50727.8009" which did have the required method signature.
EDIT: Decided to use the XMLReader version of the method. Even though we could register the newer version in the GAC(which did'nt give runtime error) from our local machine and that removed the error. but since the .NET could upgrade to a newer version and overwrite GAC we would need to be careful that the newer version would not have same problem.

Related

How to load a App.Config file into a VCL application?

I am trying the RemObject Hydra to embed a WPF module inside a VCL app.
In this WPF module, I have Grid Controls, and EntityFramework DataContext. It's connectionString, providers and everything stored in a app.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ModelConnection" connectionString="character set=UTF8;data source=localhost;initial catalog=PATHTODATABASE.FDB;user id=SYSDBA;password=MASTERKEY" providerName="FirebirdSql.Data.FirebirdClient" />
</connectionStrings>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="FirebirdSql.Data.FirebirdClient" publicKeyToken="3750abcc3150b00c" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data></configuration>
The next step was to make the VCL host with delphi then load the WPF module's .dll using the HYModuleManager component. This is pretty straigtforward :
procedure TMainForm.FormCreate(Sender: TObject);
begin
HYModuleManager1.LoadModule('%path%\to\wpf\module\GridsModule.dll');
HYModuleManager1.CreateVisualPlugin('ClientGridView', fInstance, Panel1);
end;
I run the application in Delphi. But this error is thrown :
(Translation : An exception was thrown by the target of an invocation)
So with a little more research, I run this application (HydraHost.exe) using VisualStudio, and realize that this si the exception thrown by the module :
System.InvalidOperationException : 'No connection string named 'ModelConnection' could be found in the application config file.'
I then decide to write a WPF host. I set the WPF Host App.config to include the connection string and provider infos. To no surprise, everything works fine.
So, with the VCL host, the connectionString is not found. With the WPF host, it is. My conclusion is that the app.config is not loaded by the VCL host but it is loaded by the WPF host.
So what I did next is to manually copy the WPFHost.dll.config to VCLHost.exe.config as suggested by one of the answers, but same error, connectionString is not found.
So my question is : How can I "link" a .exe.config to a VCL app built with Delphi?
You should rename your app.config to YourExeName.exe.config as it's probably now YourDllName.dll.config

Building WPF application using Microsoft.Build assemblies

I am trying to perform a build on a WPF (.Net Framework 4.0) project using the Microsoft.Build assemblies, i.e. not building from VS and not building using stock standard MSBuild from command line. All my projects build successfully, but the WPF project fails with the following message:
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9): error MSB4127: The "MarkupCompilePass1" task could not be instantiated from the assembly "PresentationBuildTasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.Windows.MarkupCompilePass1' to type 'Microsoft.Build.Framework.ITask'. [C:\Service\Test.csproj]
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.WinFx.targets(268,9): error MSB4060: The "MarkupCompilePass1" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
I have found references (on Stack Overflow) mentioning the updated MSBuild assemblies (12.0 vs 4.0) etc etc. This has all been updated, i.e. references from the build utility, but no luck.
Any ideas/suggestions?
We are using a similar system and the problem seems to stem from the compilation of the Page tag: <generator>MSBuild:Compile</generator>. This seems to be invoking MSBuild in a way that pulls the 4.0 framework libraries.
For our build executable, we simply modified the configuration to include the configurations used by the 12.0 MSBuild configuration. i.e., take the elements in C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe.config and place them in your application configuration. This resolved the issues for us.
I found a solution. Add a binding redirect to the version you want to use in your App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build.Framework" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Build" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="15.1.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Cannot parse *.Config file

In a .NET 4.5 Winforms app and using the exact code from the PayPal API doc I'm getting:
"Cannot parse *.Config file. Ensure you have configured the 'paypal' section correctly."
I'm just posting the line that causes this:
OAuthTokenCredential tokenCredential = new OAuthTokenCredential("xxxxxxxxxxxxxx", "xxxxxxxxxx");
Any ideas how to proceed?
Thanks
Since Steve chose to be obtuse, for the sake if anyone else having this issue, here is the link to a similar question which solved my problem. Might be my lack of experience working with app.config files but I had to be sure to insert the code as the first entries in the file or my HttpClient class failed on startup.
Link that put me on the right path:
Paypal c# REST API asks for an undocumented configuration section
My App.config file (basic App.config file from a new VS2013 WinForms project after adding the NuGet PayPal REST SDK Package and the parts from the solution from the link above)
As mentioned on the link as well, aaa, bbb, ccc, ddd are from your sandbox account profile.
<configSections>
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK"/>
</configSections>
<paypal>
<accounts>
<account apiUsername="aaa"
apiPassword="bbb"
applicationId="ccc"
apiSignature="ddd"/>
</accounts>
<settings>
<add name="mode" value="sandbox"/>
</settings>
</paypal>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Entity Framework on SQL Server CE without driver install

I'm developing a WPF application using Entity Framework 4 and SQL Server CE database 3.5 and it's correctly working.
However I'd like to have this application to run on a machine with .Net Framework 4 installed but without the SQL Server Compact 3.5 drivers. And no installer. Is it possible?
I have tried the following:
create a section in the app.config
<configuration>
<connectionStrings>
<add name="DbEntities"
connectionString="metadata=res://*/Model.Model1.csdl|res://*/Model.Model1.ssdl|res://*/Model.Model1.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\Data\Database1.sdf""
providerName="System.Data.EntityClient"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="SQL Server Compact Edition Data Provider"
invariant="System.Data.SqlServerCe"
description=".NET Framework Data Provider for Microsoft SQL Server Compact Edition"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
</DbProviderFactories>
</system.data>
</configuration>
add references to System.Data.SqlServerCe and System.Data.SqlServerCe.Entity and allow local copy
build the application and copy it on a machine without SQL Server CE drivers installed. When it comes to create the data context I keep getting this error :
System.ArgumentException: The specified store provider cannot be found in the configuration, or is not valid. --->
System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.
Am I losing time? Or should I just switch to SQLite?
Thanks!
EDIT:
Thanks to josemiguel.torres' answer, I check at this post detailling how to achieve this. However, I still have an assembly error.
"System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)"
So I had a look at this other post explaining how to fix this issue.
After adding some assembly binding:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
It still doesn't work ... :|
Error message is similar :
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
I'm out of solution. Anyone?
EDIT 2:
1.I have uninstalled all the Microsoft "SQL Server Compact Edition" versions from my machine.
2.I checked the machine.config version : there is no entries in the DbProviderFactories section.
3.I downloaded the 3.5 SP2 drivers from there and installed the x86 package.
4.I check my machine.config (v4 x86) and the following entries has been created under the DbProviderFactories node:
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
Why is it 3.5.0.0 and not 3.5.1.50???
juste in case: my dev machine is on Win7 x64 and target machine is WinXP x86.
Install 3.5 SP2, and modify the app.config as follows:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ChinookEntities" connectionString="metadata=res://*/Chinook.csdl|res://*/Chinook.ssdl|res://*/Chinook.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=C:\Users\erik.COMMENTOR\Documents\Visual Studio 2010\Projects\SqlCeTest\Chinook.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.3.5" />
<add name="Microsoft SQL Server Compact Data Provider 3.5" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.1.50, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xmlns="">
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="3.5.1.0-3.5.1.50" newVersion="3.5.1.50" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Make sure to use the System.Data.SqlServerCe.dll and System.Data.SqlServerCe.Entity.dll from the C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Private folder
I gave up with SQL CE 3.5 and switched to 4.0. It's working fine, thanks to this article.
Thanks Erik ;)

Silveright config error stopped

Server Error in '/' Application.
I have just started to publish the app to IIS server but it is failing, any ideas on this how to solve?
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (C:\PBM_Test\web.config line 15)
Source Error:
Line 13:
Line 14:
Line 15: Line 16:
Line 17:
Source File: C:\PBM_Test\web.config Line: 15
this is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, `enter code here`System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<validation validateIntegratedModeConfiguration
="false" />
</system.webServer>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="PBMEntities" connectionString="metadata=res://*/ModelPBM.csdl|res://*/ModelPBM.ssdl|res://*/ModelPBM.msl;provider=System.Data.SqlClient;provider connection string="data source=SRVORDERS;initial catalog=PBM;user id=OK;password=OK1;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
see http://forums.silverlight.net/t/180719.aspx/1
and http://community.discountasp.net/showthread.php?t=10296 for info
The above threads describe how you have to make sure that your web application has a copy of this file available.
If you are using a server you can install software to, the best solution is to make sure that the server has both the latest version of .net and RIA services installed (Both may be separate installations) (EDIT - make sure all the packages that alfonso list are installed.)
If you don't have access to install software on the server, the other solution is to make sure that ServiceMode.DomainServices.Hosting 4.0 is copied to the BIN folder during deployment of your ASP solution - set the file properties to Local Copy / Only if Newer
Make sure you have installed all of these packages on the server:
Silverlight4 Tools
Silverlight SDK
RiaServicesToolkit
RiaServices
Hope it helps!

Resources