Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

i have created a wcf service, which interacts with sql server using Microsoft.Sqlserver.smo. the main task of this service os to create a database from a script. while accessing the smo object for executenonquery it's throwing "Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information." error.

i tried over internet and googled, everyone said by adding certain tag in app config it will resolve the issue. But it didn't. the tag is as fallows:

XML
<startup uselegacyv2runtimeactivationpolicy="true">
    <supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0" /> 
    <requiredruntime version="v4.0" />
</startup>


still i am getting the same exception while accessing sqlserver.smo object. please provide me the solution.

i want to submit my code, but i didn't find any attachment option here. if any one is having solution for this please send me their mail id, i will send the code.
Posted
Updated 16-Jan-14 18:12pm
v2

1 solution

See: http://msdn.microsoft.com/en-us/library/aa374182(v=vs.85).aspx[^]

Especially the note:

Quote:
Names of elements and attributes are case-sensitive. The values of elements and attributes are all case-insensitive, except for the value of the type attribute.


So, uselegacyv2runtimeactivationpolicy should actually be useLegacyV2RuntimeActivationPolicy. supportedruntime should be supportedRuntime and you should not be using the requiredRuntime element in v4.0 applications.
 
Share this answer
 
v2
Comments
ChaitanyaPottam 17-Jan-14 0:23am    
Hi Ron as u specified i have done the modifications still it's throwing me the same exception. if you want i can send you the code, so that u can reach to exact point of discussion where i got struck. suggest me how could i send you my code.
Ron Beyer 17-Jan-14 0:28am    
After a little more research it seems that SMO is not available for .NET 4, even though Microsoft says the above will work, people are saying it doesn't. Looks like the only reliable fix is to downgrade your application to use 3.5. You can use PasteBin to paste your code, what are you needing SMO for?
Ron Beyer 17-Jan-14 0:33am    
If you are just running a simple database creation script, have you tried using the ADO.NET classes (SQLConnection, SQLCommand) to run it? You shouldn't need SMO just to run an SQL script.
ChaitanyaPottam 17-Jan-14 0:34am    
in my project i need to create a database in sql server, first it generates a script from existing database and then it executes the generated script to create a database in sqlserver.

one more thing Ron, i am able to do this work in a WPF application. the wpf application is of framework 4. by using the same tags in App.config i have achevied the database creation. but when i ported the same code to a wcf service i am unable to resolve the issue. could you please explain me the possible problem why it's happening.
Ron Beyer 17-Jan-14 0:38am    
When a .NET 2 application (or DLL in this case) is loaded it uses a different runtime than the .NET 4 system. In order for the two to work together it has to do something called side-by-side loading. That means that both runtimes are loaded at the same time and (I think) in the same appdomain. The reason it may work with the WPF application is that it runs at a higher trust level than your WCF service, or there may be extra restrictions on side-by-side loading for WCF services. I'm not completely sure on that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900