5

I am building an application in C# visual studio 2012 RC.

I have to run the scripts within the application. for this i am using. These two libraries. My application's target .net framework is 4.5.

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;

I wrote the code to run the scripts after checking weather database exists or not.

When i run the code an unexpected exception pops up. i really know what does it mean. Could you please help me in order to get rid of this exception.

I am attaching the my code and exception preview also.

Please HELP ME... I have googled too much already.

enter image description here

**Here are the Exception Details.**

System.IO.FileLoadException was unhandled HResult=-2146232799 Message=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. Source=mscorlib StackTrace: at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at System.Reflection.Assembly.GetType(String name, Boolean throwOnError) at Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse) at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType) at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand) at McFarlaneIndustriesPOSnamespace.SplashScreen.CreateDatabase() in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\SplashScreen.cs:line 139 at McFarlaneIndustriesPOSnamespace.SplashScreen.splashScreenTimer_Tick(Object sender, EventArgs e) in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\SplashScreen.cs:line 159 at System.Windows.Forms.Timer.OnTick(EventArgs e) at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at McFarlaneIndustriesPOSnamespace.Program.Main() in e:\Works\McFarlane Industries\McFarlane Industries Point of Sale Source Code\McFarlaneIndustries\Program.cs:line 19 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) at System.Activator.CreateInstance(ActivationContext activationContext) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

2
  • Please post the exception details Commented Jul 1, 2012 at 22:15
  • I have edited the question and adds the exception details as you asked for. The snapshot shows the point on which the exception pops up. Please see the details and snapshot too. Commented Jul 1, 2012 at 22:23

1 Answer 1

5

It looks like you're trying to load .net 2 version of Microsoft.SqlServer.xxxx.dll. Update your references to a .net4 version (preferable), or add the following mantra to your app.config under the <configuration> node

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  <requiredRuntime version="v4.0" />
</startup>

to allow loading of .net 2 assemblies. See here for details.

Sign up to request clarification or add additional context in comments.

4 Comments

These two libraries referenced in my project was not there in my assembly. then i download the MSI file "SharedManagementObjects.msi" x64 for sql server 2008 R2. after that this exception pops up. now i am going to download this file from sql server 2012 webpage. i hope now .net clash doesn't comes. am i going right sir. do i really installs it. or some thing else. is this the right way.
Let us know if sqlsvr2012 has .net 4 SMO API. If not, use the app.config modifications to get things working.
You are great ... you the best ... you are great... sir... I am you fan now... My problem is solved... Thanks .. alot. alot alot alot alot alot...
Solubion: I have installed the Microsoft management object sql Server 2012 form official website. and installs it on my pc. then i place that code in my app.config. file .. now it works and database is installed successfully... thanks to spender ... really thanks to him.. i spend alot of time on this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.