I'm develop an application desktop with C# Visual Studio 2017 with .net framework 4.6.1 and consume odata api.
I'm using OData Client Code Generator to create a proxy, and use Trippin Service for simulation (https://services.odata.org/V4/(S(v35us2ydb4upkphl4id2qpwx))/TripPinServiceRW/).
In my development machine everything is great. When deploy to a fresh machine (Windows 7 + Framework 4.6.1) with click once publisher, horrible problem occurred.
System.TypeInitializationException: The type initializer for 'ClientEdmModelCache' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
Below is simple code only a button and listbox
private void button1_Click(object sender, EventArgs e)
{
var container = new DefaultContainer(new Uri("https://services.odata.org/V4/(S(v35us2ydb4upkphl4id2qpwx))/TripPinServiceRW/"));
var stores = container.Airlines.ToList();
foreach (var item in stores)
{
listBox1.Items.Add(item.AirlineCode + " - " + item.Name);
}
}
as
I expect result something like this
AA - American Airlines
FM - Shanghai Airlines
etc..
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.TypeInitializationException: The type initializer for 'ClientEdmModelCache' threw an exception. ---> System.BadImageFormatException: Could not load file or assembly 'System.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058) ---> System.BadImageFormatException: Cannot load a reference assembly for execution. --- End of inner exception stack trace ---
at Microsoft.OData.Edm.Vocabularies.EdmDirectValueAnnotationsManager.SetAnnotation(IEnumerable`1 immutableAnnotations, Object& transientAnnotations, String namespaceName, String localName, Object value)
at Microsoft.OData.Edm.Vocabularies.EdmDirectValueAnnotationsManager.SetAnnotationValue(IEdmElement element, String namespaceName, String localName, Object value, VersioningDictionary`2& annotationsDictionary)
at Microsoft.OData.Edm.Vocabularies.EdmDirectValueAnnotationsManager.SetAnnotationValue(IEdmElement element, String namespaceName, String localName, Object value)
at Microsoft.OData.Edm.ExtensionMethods.SetAnnotationValue(IEdmModel model, IEdmElement element, String namespaceName, String localName, Object value)
at Microsoft.OData.Edm.ExtensionMethods.SetEdmVersion(IEdmModel model, Version version)
at Microsoft.OData.Client.DataServiceContext.ClientEdmModelCache.CreateClientEdmModelCache()
at Microsoft.OData.Client.DataServiceContext.ClientEdmModelCache..cctor()
User contributions licensed under CC BY-SA 3.0