يطرح WCF استثناء FileNotFound لـ "System.ServiceModel" عند إنشاء ServiceHost

StackOverflow https://stackoverflow.com/questions/934980

سؤال

أواجه مشكلة غريبة حقًا مع WCF.لدي مشروعان في أحد الحلول، كل منهما يبدأ بعض خدمات WCF المستضافة ذاتيًا.

مشروع 1:

myService = new ServiceHost(typeof(MyService1));

الذي يسير بشكل جيد.ومع ذلك، عندما أحاول تشغيل مشروعي الثاني، والذي يحتوي على:

meService = new ServiceHost(typeof(MyOtherService));

أحصل على الاستثناء:

FileNotFoundException
Could not load file or assembly 'System.ServiceModel' or one of its dependencies.
The system cannot find the file specified.":"System.ServiceModel

سجل الانصهار:

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel
 (Partial)
LOG: Appbase = file:///C:/Work/MySln/MyProj/bin/Dev
LOG: Initial PrivatePath = NULL
Calling assembly : System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\MyProj\bin\Dev\MyProj.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///C:/Work/MySln/MyProj/bin/Dev/System.ServiceModel/System.ServiceModel.EXE.

الجزء الغريب حقًا هو أنه في مصحح الأخطاء، في الوقت الذي أحصل فيه على هذا الاستثناء، يمكنني الانتقال إلى "QuickWatch" في Visual Studio وإدخال:

new MyOtherService()  // returns new instance properly
new ServiceHost()     // returns new instance properly
new ServiceHost(typeof(MyOtherService))  // throws exception, same as above.

لقد حاولت تشغيل SysInternals File System Watcher أثناء تصحيح الأخطاء، لكنه لم يظهر أي أخطاء 'FileNotFound' بخلاف محاولة devenv.exe تعقب ملفات .pdb لإنشاء تتبع المكدس.

هل لدى أي شخص أي أفكار أخرى حول ما يجب النظر إليه؟


التحديث رقم 1

لقد قمت بفحص سجل الدمج لهذه العملية، ويبدو أن شيئًا غريبًا قد حدث.يوجد إدخالان للسجل لـ System.ServiceModel، من الخلف إلى الخلف:

*** Assembly Binder Log Entry  (6/1/2009 @ 10:26:48 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files\TestDriven.NET 2.0\ProcessInvocation.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
 (Fully-specified)
LOG: Appbase = file:///C:/Work/MySln/PFWebIntgTests/bin/Dev
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Documents and Settings\removed\Local Settings\Temp\TestDrivenShadowCopy\633794488082894732
LOG: AppName = domain-nunit.addin.dll
Calling assembly : PFWebIntgTests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\PFWebIntgTests\bin\Dev\PFWebIntgTests.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\WINDOWS\assembly\GAC_MSIL\System.ServiceModel\3.0.0.0__b77a5c561934e089\System.ServiceModel.dll.
LOG: Assembly is loaded in default load context.

ثم الإدخال الثاني:

*** Assembly Binder Log Entry  (6/1/2009 @ 10:26:52 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files\TestDriven.NET 2.0\ProcessInvocation.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = removed\removed
LOG: DisplayName = System.ServiceModel
 (Partial)
LOG: Appbase = file:///C:/Work/MySln/PFWebIntgTests/bin/Dev
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Documents and Settings\removed\Local Settings\Temp\TestDrivenShadowCopy\633794488082894732
LOG: AppName = domain-nunit.addin.dll
Calling assembly : System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Work\MySln\PFWebIntgTests\bin\Dev\PFWebIntgTests.dll.temp.config
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel/System.ServiceModel.DLL.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel.EXE.
LOG: Attempting download of new URL file:///C:/Work/MySln/PFWebIntgTests/bin/Dev/System.ServiceModel/System.ServiceModel.EXE.
LOG: All probing URLs attempted and failed.

لذا يبدو أنه يحاول تحميل System.ServiceModel مرتين، ومرة ​​واحدة من دليل التطبيق المحلي بدلاً من GAC؟أنا مرتبك...

هل كانت مفيدة؟

المحلول

وجدت مشكلتي:

بالنسبة لكلا المشروعين (دعنا نسميهما MyProj1 وMyProj2) لدي هذا السطر في ملف .dll.config:

<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="System.ServiceModel.ServiceAuthorizationManager, System.ServiceModel" />

يعمل Proj1 بشكل جيد، ويفشل Proj2 مع الاستثناء أعلاه.لسبب ما في Proj2 فقط، فإنه يظهر فقط في المجلد ‎\bin الخاص بي عند محاولة حل "System.ServiceModel".

إذا قمت بتغيير السطر أعلاه للحصول على اسم التجميع الكامل:

<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="System.ServiceModel.ServiceAuthorizationManager, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

كل شيء يعمل مرة أخرى.كيف الغريب...ليس لدي أي فكرة عن سبب عمل مرجع التكوين نفسه لمشروع واحد وليس لمشروع آخر، ولكن مهلا...على الأقل أستطيع العودة إلى العمل الآن :)

نصائح أخرى

مجموعة من الاسئلة:

  • هل يستهدف كلا المشروعين .NET Framework 3.0 على الأقل أو أعلى؟
  • هل يمكنك أن توضح لنا الواجهات التي تنفذها الخدمتان والمخطط التقريبي لفئات تنفيذ الخدمة نفسها؟

سأحاول حذف المرجع وإعادة إضافته في المشروع الثاني إلى مجموعة System.ServiceModel.ربما أضافه مطور آخر باستخدام ملف محلي بدلاً من إصدار GAC مما تسبب في حدوث مشكلات في بيئتك المحلية؟

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top