This is my situation: I am using Visual Studio 2015 with .NET Framework 4.6.1 on a Win 10 64-bit machine for building a WCF Service.
In my solution I have several different project types, mainly plain C# Class Library
(class libraries), some C++
-dll references, and of course the WCF Service Library
itself.
Before I continue I would like to state that this is my first date with WCF ever...
This SO question is addressing a similar problem, Where is the startup method of a WCF Service?, but since I'm dealing with a WCF Service Library
a couple of years later when the original question was asked, and the fact that the original question is not using the same project type, I believe that (?) the answer there is not adaptable for my problem. Not when just debugging at least?
In my solution, I have set my WCF Service Library
-project as StartUp project. When hitting the F5-key (for Start), this is what I get:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
Ok, normally, in a plain C# Console Application
, I would have set up a try-catch-block in the Main()
-method in order to examine my problem. But my WCF Service Library
-project doesn't seem to have such.
My question: How can I find out what the LoaderException
property is?
EDIT 1: I tried @user497745's answer (both proposals) and the first one helped me:
WCF Class Library
.App.config
:<system.serviceModel> <diagnostics> <messageLogging logEntireMessage="true" logMalformedMessages="false" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="false" maxMessagesToLog="3000" maxSizeOfMessageToLog="2000"/> </diagnostics> <behaviors> <serviceBehaviors> <behavior name="HemsamaritenServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> <services> <!-- This section is optional with the new configuration model introduced in .NET Framework 4. --> <service name="WCFServiceLibrary.HemsamaritenDuplexService" behaviorConfiguration="HemsamaritenServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8000/Hemsamariten/service"/> </baseAddresses> </host> <!-- this endpoint is exposed at the base address provided by host: http://localhost:8000/Hemsamariten/service --> <endpoint address="" binding="wsDualHttpBinding" contract="WCFServiceLibrary.Interfaces.IHemsamaritenDuplexService" /> <!-- the mex endpoint is exposed at http://localhost:8000/Hemsamariten/service/mex --> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="All" propagateActivity="true"> <listeners> <add name="xml" /> </listeners> </source> <source name="System.ServiceModel.MessageLogging" switchValue="All"> <listeners> <add name="xml" /> </listeners> </source> </sources> <sharedListeners> <add initializeData="C:\Users\haunsTM\Desktop\WinService\debuglog.svclog" type="System.Diagnostics.XmlWriterTraceListener" name="xml" /> </sharedListeners> <trace autoflush="true" /> </system.diagnostics>
C:\Users\haunsTM\Desktop\WinService\debuglog.svclog
, was empty after the run.So, if you're trying to break in the debugger to catch the error as it happens, I would recommend a different approach.
Either:
Go to DEBUG > Exceptions and select Common Language Runtime Exceptions > System.Reflection and check the exact exception type you're getting. I'm not sure if you also need to un-check "Enable Just my Code" in DEBUG > Options. And perhaps check "Enable .NET Framework source stepping." Then when the exception occurs, Visual Studio should break and allow you to see the exception details like you would any exception.
Add diagnostics tracing by adding the below to you App.config file for the WCF Class Library. Then try to start the library, and after you get the error, stop the debugger and open up the generated tracefile (which is located in whatever path and filename you chose below) in the SvcTraceViewer. You can open Visual Studio Developer Command Prompt and launch it from there.
<system.serviceModel>
<diagnostics>
<messageLogging
logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000"/>
</diagnostics>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All"
propagateActivity="true">
<listeners>
<add name="xml" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xml" />
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="[SOME_PATH]\[SOME_FILENAME].svclog" type="System.Diagnostics.XmlWriterTraceListener"
name="xml" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>