I have changed target framework from <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
to <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
for a C++ project.
And now I'm getting an exception:
Exception thrown: 'System.Configuration.ConfigurationErrorsException' in System.Configuration.dll log4net:ERROR Exception while reading ConfigurationSettings. Check your .config file is well formed XML.
System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.TypeInitializationException: The type initializer for 'System.Uri' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.UriParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Runtime.Versioning.BinaryCompatibility' threw an exception. ---> System.ArgumentException: String cannot be of zero length. Parameter name: frameworkName at System.Runtime.Versioning.BinaryCompatibility.ParseFrameworkName(String frameworkName, String& identifier, Int32& version, String& profile)
at System.Runtime.Versioning.BinaryCompatibility.ParseTargetFrameworkMonikerIntoEnum(String targetFrameworkMoniker, TargetFrameworkId& targetFramework, Int32& targetFrameworkVersion) at System.Runtime.Versioning.BinaryCompatibility.ReadTargetFrameworkId() at System.Runtime.Versioning.BinaryCompatibility.get_AppWasBuiltForFramework() at System.Runtime.Versioning.BinaryCompatibility..cctor() --- End of inner exception stack trace --- at System.UriParser..cctor()
--- End of inner exception stack trace --- at System.Uri..cctor() --- End of inner exception stack trace --- at System.Configuration.ClientConfigurationSystem..ctor() at System.Configuration.ConfigurationManager.EnsureConfigurationSystem() --- End of inner exception stack trace --- at System.Configuration.ConfigurationManager.PrepareConfigSystem() at System.Configuration.ConfigurationManager.get_AppSettings() at log4net.Util.SystemInfo.GetAppSetting(String key)
My investigation gives me the reason: while compilation VS2015 adds [assembly: TargetFramework("", FrameworkDisplayName = "")]
. That's why I can't add the correct TargetFrameworkAttribute
manually. And this automatically added attribute causes an exception as the target framework can't be an empty string.
Do you have any advice, on how could I fix this problem?
Update:
Well, I've enabled logging as Hans Passant said. But I had no luck. As there was no word about .Net 4.0 and Visual Studio created correct file %temp%\.NETFramework,Version=v4.8.AssemblyAttributes.cpp
, but the content of the file:
#using <mscorlib.dll> [assembly: System::Runtime::Versioning::TargetFrameworkAttribute(L"", FrameworkDisplayName=L"")];
Nevertheless, I found a hack - I'm adding the required attribute manually. To do it I defined a variable in the project file:
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
This variable avoids the automatic creation of the TargetFrameworkAttribute
. So I can add the correct attribute from my code:
[assembly:TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")];
With this workaround, I can start the application and it seems to work everything... but I do not really like it.