none
WCF Service Library - VS 2010 not working RRS feed

  • Question

  • HI,

    When I am creating a new WCF project located at network drive using VS 2010 and trying to run the same, I am getting following error:

    ***********

    System.IO.FileLoadException: Could not load file or assembly 'file:///U:\Workspace\temp\WcfServiceLibrary1\WcfServiceLibrary1\bin\Debug\WcfServiceLibrary1.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
    File name: 'file:///U:\Workspace\temp\WcfServiceLibrary1\WcfServiceLibrary1\bin\Debug\WcfServiceLibrary1.dll' ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.

    *********

    It's not working even after amending the WCF config file and including "<loadFromRemoteSources enabled="false"/>".

    Please note that I am using Vs 2010 and .NET 3.5. This is not working even with .NET 4.0.

    Also, if follow the same steps with VS 2008, it is working fine.

     

    Friday, July 30, 2010 11:42 AM

Answers

  • Steven- Thanks for your help. I am finally able to resolve it as below:

    Note: We need following setting in order to run a WCF service located in network location, using VS 2010 WCF service host. 

    1. Go to C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE   ( Assuming, you have installed VS 2010 to c:/ drive)
    2. Open "WcfSvcHost.exe.config"
    3. Add to the config file (between runtime tag)

    <loadFromRemoteSources enabled="true"/>

    Actually, VS 2010, uses the WcfSvcHost.exe from above location irrespective of the .NET framework that you have selected to compile and run your WCF executable.

    Note: VS 2008 uses the WcfSvcHost.exe from the location "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE" and we are not required to make any change to corresponding config file.

     

     

     

    Monday, August 9, 2010 10:00 AM

All replies

  • Hello,

    did you try <loadFromRemoteSources enabled="true" />?

    Best regards,
    Ladislav

    Friday, July 30, 2010 12:19 PM
  • Hi a22kappor,

    The problem you encounter is a typical .NET CAS problem. As the error info explained, in .NET 4, by default loading source code from remote drive location is prohibited. Intead of setting <LoadFromRemoteSources enabled /> to false, you shoud set it to true so as to make the remote code/assemblies loadable.

    <configuration>
      <runtime>
       <loadFromRemoteSources enabled="true"/>
      </runtime>
    </configuration>
    
    

    Also, even if you turn on it and successfully loaded the assemblies from remote share folder, they are running in partial trust mode which is restricted to many privileged operations on local machine. I suggest you take a look at the code access security policy information about .NET 4.0 for more ideas:


    #Coding with Security Policy in .NET 4.0 – Implicit uses of CAS policy
    http://blogs.msdn.com/b/shawnfa/archive/2009/05/27/coding-with-security-policy-in-net-4-0-implicit-uses-of-cas-policy.aspx

    #Exploring the .NET Framework 4 Security Model
    http://msdn.microsoft.com/en-us/magazine/ee677170.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Monday, August 2, 2010 8:11 AM
    Moderator
  •  Thanks for your responses!

    It's still not working even after setting the <loadFromRemoteSources enabled="true"/>.

    My question is, if I use VS 2010 with .NET 3.5, do I need to do these settings as same application is working fine with VS2008 and .NET 4.0. I am not sure if I am missing anything here. Do I need to go through the links provided by Steven related "code access security policy information about .NET 4.0" as I am on .NET 3.5? Thanks!

     

     

     

     

     

     

     

     

    Monday, August 2, 2010 8:25 AM
  • Hi,

    Though you've referenced the .NET 3.5 framework version in your VS 2010 project, from the error message, it seems the runtime is still using .NET framework 2.0's CLR(the same for .NET 3.0 and 3.5). Therefore, I think you will still need to follow the .NET 4.0's security policy.

    When you using VS 2008 with .NET 3.5, the CLR version loaded for running application is 2.0 version.

    BTW, you can try use app.config file to specify a runtime version and force the application to run under the CLR of that version:

    #CLR changes in .NET Framework 4.0
    http://balaweblog.com/2010/05/clr-changes-in-net-framework-4-0/


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 9, 2010 2:25 AM
    Moderator
  • Steven- Thanks for your help. I am finally able to resolve it as below:

    Note: We need following setting in order to run a WCF service located in network location, using VS 2010 WCF service host. 

    1. Go to C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE   ( Assuming, you have installed VS 2010 to c:/ drive)
    2. Open "WcfSvcHost.exe.config"
    3. Add to the config file (between runtime tag)

    <loadFromRemoteSources enabled="true"/>

    Actually, VS 2010, uses the WcfSvcHost.exe from above location irrespective of the .NET framework that you have selected to compile and run your WCF executable.

    Note: VS 2008 uses the WcfSvcHost.exe from the location "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE" and we are not required to make any change to corresponding config file.

     

     

     

    Monday, August 9, 2010 10:00 AM