The type initializer for 'System.Net.ComNetOS' threw an exception


  • i am still facing this problem "The type initializer for 'System.Net.ComNetOS' threw an exception" after i convert solution from framework V2.0 to V4.0 in 2010 ultimate.

    i checked even the App.Config too ,all things is right .i will copy the full error message :


    System.TypeInitializationException was unhandled
      Message=The type initializer for 'System.Net.ComNetOS' threw an exception. 
     Source=System   TypeName=System.Net.ComNetOS
           at System.Net.Sockets.Socket.InitializeSockets()
           at System.Net.Sockets.Socket.get_OSSupportsIPv4()
           at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(IDictionary properties, IServerChannelSinkProvider sinkProvider, IAuthorizeRemotingConnection authorizeCallback)
           at System.Runtime.Remoting.Channels.Tcp.TcpServerChannel..ctor(IDictionary properties, IServerChannelSinkProvider sinkProvider)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.RegisterChannel(ChannelType ChannelType, Boolean ChannelIsSecure)
           at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)


    please , anyone can help me on this.? i am waitting !

    Wednesday, February 15, 2012 1:40 PM

All replies

  • You can try rebuilding the application with a new version number and see whether it makes difference.

    DeVa, M.S., {MSFT} Please remember to mark the replies as answers if they help

    Friday, February 17, 2012 7:01 PM
  • thanks Deva for your replay ..

    Rebuild All Succeeded but in the time or run  this message is apeare "The type initializer for 'System.Net.ComNetOS' threw an exception" .

    i converted all application to 4.0 ,but only in the time of run i am facing that problem ... please help.

    Saturday, February 18, 2012 10:57 AM
  • after long RnD , it's solved after i remove the following code from app.config :

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

    but in other project inside my solution i am start to face same problem before.

    i am sure that all projects are converted successfully to v4.0

    • Edited by FVBS Saturday, February 18, 2012 12:42 PM
    Saturday, February 18, 2012 12:21 PM
  • Checking the app.config will be the key in these type of scenarios. You can also try comparing the migrated project app.config with newly created project's app.config and see the difference. Finally, you can give a tryby rebuilding the application with new version numbers...

    DeVa, M.S., {MSFT} Please remember to mark the replies as answers if they help

    Thursday, February 23, 2012 4:35 AM
  • I removed the following line from the web.config file and It worked for me 

     <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
              <filter />

    Thursday, July 10, 2014 3:54 PM